mdwysiwyg 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,3909 @@
1
+ // src/components/MarkdownEditor/MarkdownEditor.tsx
2
+ import { useMemo, useRef as useRef7, useState as useState8 } from "react";
3
+ import { useEditor } from "@tiptap/react";
4
+ import { getMarkRange } from "@tiptap/core";
5
+
6
+ // src/components/MarkdownEditor/markdown/tiptapMarkdownBridge.ts
7
+ import { Node } from "@tiptap/core";
8
+ import StarterKit from "@tiptap/starter-kit";
9
+ import Table from "@tiptap/extension-table";
10
+ import TableRow from "@tiptap/extension-table-row";
11
+ import TableCell from "@tiptap/extension-table-cell";
12
+ import TableHeader from "@tiptap/extension-table-header";
13
+ import TaskList from "@tiptap/extension-task-list";
14
+ import TaskItem from "@tiptap/extension-task-item";
15
+ import Link from "@tiptap/extension-link";
16
+ import Image from "@tiptap/extension-image";
17
+ import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
18
+ import { createLowlight } from "lowlight";
19
+
20
+ // node_modules/highlight.js/es/languages/json.js
21
+ var EXTENDED_NUMBER_RE = "([-+]?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)|NaN|[-+]?Infinity";
22
+ var EXTENDED_NUMBER_MODE = {
23
+ scope: "number",
24
+ match: EXTENDED_NUMBER_RE,
25
+ relevance: 0
26
+ };
27
+ function json(hljs) {
28
+ const ATTRIBUTE = {
29
+ className: "attr",
30
+ begin: /(("(\\.|[^\\"\r\n])*")|('(\\.|[^\\'\r\n])*'))(?=\s*:)/,
31
+ relevance: 1.01
32
+ };
33
+ const PUNCTUATION = {
34
+ match: /[{}[\],:]/,
35
+ className: "punctuation",
36
+ relevance: 0
37
+ };
38
+ const LITERALS3 = [
39
+ "true",
40
+ "false",
41
+ "null"
42
+ ];
43
+ const LITERALS_MODE = {
44
+ scope: "literal",
45
+ beginKeywords: LITERALS3.join(" ")
46
+ };
47
+ return {
48
+ name: "JSON",
49
+ aliases: ["jsonc", "json5"],
50
+ keywords: {
51
+ literal: LITERALS3
52
+ },
53
+ contains: [
54
+ ATTRIBUTE,
55
+ PUNCTUATION,
56
+ hljs.APOS_STRING_MODE,
57
+ hljs.QUOTE_STRING_MODE,
58
+ LITERALS_MODE,
59
+ EXTENDED_NUMBER_MODE,
60
+ hljs.C_LINE_COMMENT_MODE,
61
+ hljs.C_BLOCK_COMMENT_MODE
62
+ ],
63
+ illegal: "\\S"
64
+ };
65
+ }
66
+
67
+ // node_modules/highlight.js/es/languages/sql.js
68
+ function sql(hljs) {
69
+ const regex = hljs.regex;
70
+ const COMMENT_MODE = hljs.COMMENT("--", "$");
71
+ const STRING = {
72
+ scope: "string",
73
+ variants: [
74
+ {
75
+ begin: /'/,
76
+ end: /'/,
77
+ contains: [{ match: /''/ }]
78
+ }
79
+ ]
80
+ };
81
+ const QUOTED_IDENTIFIER = {
82
+ begin: /"/,
83
+ end: /"/,
84
+ contains: [{ match: /""/ }]
85
+ };
86
+ const LITERALS3 = [
87
+ "true",
88
+ "false",
89
+ // Not sure it's correct to call NULL literal, and clauses like IS [NOT] NULL look strange that way.
90
+ // "null",
91
+ "unknown"
92
+ ];
93
+ const MULTI_WORD_TYPES = [
94
+ "double precision",
95
+ "large object",
96
+ "with timezone",
97
+ "without timezone"
98
+ ];
99
+ const TYPES3 = [
100
+ "bigint",
101
+ "binary",
102
+ "blob",
103
+ "boolean",
104
+ "char",
105
+ "character",
106
+ "clob",
107
+ "date",
108
+ "dec",
109
+ "decfloat",
110
+ "decimal",
111
+ "float",
112
+ "int",
113
+ "integer",
114
+ "interval",
115
+ "nchar",
116
+ "nclob",
117
+ "national",
118
+ "numeric",
119
+ "real",
120
+ "row",
121
+ "smallint",
122
+ "time",
123
+ "timestamp",
124
+ "varchar",
125
+ "varying",
126
+ // modifier (character varying)
127
+ "varbinary"
128
+ ];
129
+ const NON_RESERVED_WORDS = [
130
+ "add",
131
+ "asc",
132
+ "collation",
133
+ "desc",
134
+ "final",
135
+ "first",
136
+ "last",
137
+ "view"
138
+ ];
139
+ const RESERVED_WORDS = [
140
+ "abs",
141
+ "acos",
142
+ "all",
143
+ "allocate",
144
+ "alter",
145
+ "and",
146
+ "any",
147
+ "are",
148
+ "array",
149
+ "array_agg",
150
+ "array_max_cardinality",
151
+ "as",
152
+ "asensitive",
153
+ "asin",
154
+ "asymmetric",
155
+ "at",
156
+ "atan",
157
+ "atomic",
158
+ "authorization",
159
+ "avg",
160
+ "begin",
161
+ "begin_frame",
162
+ "begin_partition",
163
+ "between",
164
+ "bigint",
165
+ "binary",
166
+ "blob",
167
+ "boolean",
168
+ "both",
169
+ "by",
170
+ "call",
171
+ "called",
172
+ "cardinality",
173
+ "cascaded",
174
+ "case",
175
+ "cast",
176
+ "ceil",
177
+ "ceiling",
178
+ "char",
179
+ "char_length",
180
+ "character",
181
+ "character_length",
182
+ "check",
183
+ "classifier",
184
+ "clob",
185
+ "close",
186
+ "coalesce",
187
+ "collate",
188
+ "collect",
189
+ "column",
190
+ "commit",
191
+ "condition",
192
+ "connect",
193
+ "constraint",
194
+ "contains",
195
+ "convert",
196
+ "copy",
197
+ "corr",
198
+ "corresponding",
199
+ "cos",
200
+ "cosh",
201
+ "count",
202
+ "covar_pop",
203
+ "covar_samp",
204
+ "create",
205
+ "cross",
206
+ "cube",
207
+ "cume_dist",
208
+ "current",
209
+ "current_catalog",
210
+ "current_date",
211
+ "current_default_transform_group",
212
+ "current_path",
213
+ "current_role",
214
+ "current_row",
215
+ "current_schema",
216
+ "current_time",
217
+ "current_timestamp",
218
+ "current_path",
219
+ "current_role",
220
+ "current_transform_group_for_type",
221
+ "current_user",
222
+ "cursor",
223
+ "cycle",
224
+ "date",
225
+ "day",
226
+ "deallocate",
227
+ "dec",
228
+ "decimal",
229
+ "decfloat",
230
+ "declare",
231
+ "default",
232
+ "define",
233
+ "delete",
234
+ "dense_rank",
235
+ "deref",
236
+ "describe",
237
+ "deterministic",
238
+ "disconnect",
239
+ "distinct",
240
+ "double",
241
+ "drop",
242
+ "dynamic",
243
+ "each",
244
+ "element",
245
+ "else",
246
+ "empty",
247
+ "end",
248
+ "end_frame",
249
+ "end_partition",
250
+ "end-exec",
251
+ "equals",
252
+ "escape",
253
+ "every",
254
+ "except",
255
+ "exec",
256
+ "execute",
257
+ "exists",
258
+ "exp",
259
+ "external",
260
+ "extract",
261
+ "false",
262
+ "fetch",
263
+ "filter",
264
+ "first_value",
265
+ "float",
266
+ "floor",
267
+ "for",
268
+ "foreign",
269
+ "frame_row",
270
+ "free",
271
+ "from",
272
+ "full",
273
+ "function",
274
+ "fusion",
275
+ "get",
276
+ "global",
277
+ "grant",
278
+ "group",
279
+ "grouping",
280
+ "groups",
281
+ "having",
282
+ "hold",
283
+ "hour",
284
+ "identity",
285
+ "in",
286
+ "indicator",
287
+ "initial",
288
+ "inner",
289
+ "inout",
290
+ "insensitive",
291
+ "insert",
292
+ "int",
293
+ "integer",
294
+ "intersect",
295
+ "intersection",
296
+ "interval",
297
+ "into",
298
+ "is",
299
+ "join",
300
+ "json_array",
301
+ "json_arrayagg",
302
+ "json_exists",
303
+ "json_object",
304
+ "json_objectagg",
305
+ "json_query",
306
+ "json_table",
307
+ "json_table_primitive",
308
+ "json_value",
309
+ "lag",
310
+ "language",
311
+ "large",
312
+ "last_value",
313
+ "lateral",
314
+ "lead",
315
+ "leading",
316
+ "left",
317
+ "like",
318
+ "like_regex",
319
+ "listagg",
320
+ "ln",
321
+ "local",
322
+ "localtime",
323
+ "localtimestamp",
324
+ "log",
325
+ "log10",
326
+ "lower",
327
+ "match",
328
+ "match_number",
329
+ "match_recognize",
330
+ "matches",
331
+ "max",
332
+ "member",
333
+ "merge",
334
+ "method",
335
+ "min",
336
+ "minute",
337
+ "mod",
338
+ "modifies",
339
+ "module",
340
+ "month",
341
+ "multiset",
342
+ "national",
343
+ "natural",
344
+ "nchar",
345
+ "nclob",
346
+ "new",
347
+ "no",
348
+ "none",
349
+ "normalize",
350
+ "not",
351
+ "nth_value",
352
+ "ntile",
353
+ "null",
354
+ "nullif",
355
+ "numeric",
356
+ "octet_length",
357
+ "occurrences_regex",
358
+ "of",
359
+ "offset",
360
+ "old",
361
+ "omit",
362
+ "on",
363
+ "one",
364
+ "only",
365
+ "open",
366
+ "or",
367
+ "order",
368
+ "out",
369
+ "outer",
370
+ "over",
371
+ "overlaps",
372
+ "overlay",
373
+ "parameter",
374
+ "partition",
375
+ "pattern",
376
+ "per",
377
+ "percent",
378
+ "percent_rank",
379
+ "percentile_cont",
380
+ "percentile_disc",
381
+ "period",
382
+ "portion",
383
+ "position",
384
+ "position_regex",
385
+ "power",
386
+ "precedes",
387
+ "precision",
388
+ "prepare",
389
+ "primary",
390
+ "procedure",
391
+ "ptf",
392
+ "range",
393
+ "rank",
394
+ "reads",
395
+ "real",
396
+ "recursive",
397
+ "ref",
398
+ "references",
399
+ "referencing",
400
+ "regr_avgx",
401
+ "regr_avgy",
402
+ "regr_count",
403
+ "regr_intercept",
404
+ "regr_r2",
405
+ "regr_slope",
406
+ "regr_sxx",
407
+ "regr_sxy",
408
+ "regr_syy",
409
+ "release",
410
+ "result",
411
+ "return",
412
+ "returns",
413
+ "revoke",
414
+ "right",
415
+ "rollback",
416
+ "rollup",
417
+ "row",
418
+ "row_number",
419
+ "rows",
420
+ "running",
421
+ "savepoint",
422
+ "scope",
423
+ "scroll",
424
+ "search",
425
+ "second",
426
+ "seek",
427
+ "select",
428
+ "sensitive",
429
+ "session_user",
430
+ "set",
431
+ "show",
432
+ "similar",
433
+ "sin",
434
+ "sinh",
435
+ "skip",
436
+ "smallint",
437
+ "some",
438
+ "specific",
439
+ "specifictype",
440
+ "sql",
441
+ "sqlexception",
442
+ "sqlstate",
443
+ "sqlwarning",
444
+ "sqrt",
445
+ "start",
446
+ "static",
447
+ "stddev_pop",
448
+ "stddev_samp",
449
+ "submultiset",
450
+ "subset",
451
+ "substring",
452
+ "substring_regex",
453
+ "succeeds",
454
+ "sum",
455
+ "symmetric",
456
+ "system",
457
+ "system_time",
458
+ "system_user",
459
+ "table",
460
+ "tablesample",
461
+ "tan",
462
+ "tanh",
463
+ "then",
464
+ "time",
465
+ "timestamp",
466
+ "timezone_hour",
467
+ "timezone_minute",
468
+ "to",
469
+ "trailing",
470
+ "translate",
471
+ "translate_regex",
472
+ "translation",
473
+ "treat",
474
+ "trigger",
475
+ "trim",
476
+ "trim_array",
477
+ "true",
478
+ "truncate",
479
+ "uescape",
480
+ "union",
481
+ "unique",
482
+ "unknown",
483
+ "unnest",
484
+ "update",
485
+ "upper",
486
+ "user",
487
+ "using",
488
+ "value",
489
+ "values",
490
+ "value_of",
491
+ "var_pop",
492
+ "var_samp",
493
+ "varbinary",
494
+ "varchar",
495
+ "varying",
496
+ "versioning",
497
+ "when",
498
+ "whenever",
499
+ "where",
500
+ "width_bucket",
501
+ "window",
502
+ "with",
503
+ "within",
504
+ "without",
505
+ "year"
506
+ ];
507
+ const RESERVED_FUNCTIONS = [
508
+ "abs",
509
+ "acos",
510
+ "array_agg",
511
+ "asin",
512
+ "atan",
513
+ "avg",
514
+ "cast",
515
+ "ceil",
516
+ "ceiling",
517
+ "coalesce",
518
+ "corr",
519
+ "cos",
520
+ "cosh",
521
+ "count",
522
+ "covar_pop",
523
+ "covar_samp",
524
+ "cume_dist",
525
+ "dense_rank",
526
+ "deref",
527
+ "element",
528
+ "exp",
529
+ "extract",
530
+ "first_value",
531
+ "floor",
532
+ "json_array",
533
+ "json_arrayagg",
534
+ "json_exists",
535
+ "json_object",
536
+ "json_objectagg",
537
+ "json_query",
538
+ "json_table",
539
+ "json_table_primitive",
540
+ "json_value",
541
+ "lag",
542
+ "last_value",
543
+ "lead",
544
+ "listagg",
545
+ "ln",
546
+ "log",
547
+ "log10",
548
+ "lower",
549
+ "max",
550
+ "min",
551
+ "mod",
552
+ "nth_value",
553
+ "ntile",
554
+ "nullif",
555
+ "percent_rank",
556
+ "percentile_cont",
557
+ "percentile_disc",
558
+ "position",
559
+ "position_regex",
560
+ "power",
561
+ "rank",
562
+ "regr_avgx",
563
+ "regr_avgy",
564
+ "regr_count",
565
+ "regr_intercept",
566
+ "regr_r2",
567
+ "regr_slope",
568
+ "regr_sxx",
569
+ "regr_sxy",
570
+ "regr_syy",
571
+ "row_number",
572
+ "sin",
573
+ "sinh",
574
+ "sqrt",
575
+ "stddev_pop",
576
+ "stddev_samp",
577
+ "substring",
578
+ "substring_regex",
579
+ "sum",
580
+ "tan",
581
+ "tanh",
582
+ "translate",
583
+ "translate_regex",
584
+ "treat",
585
+ "trim",
586
+ "trim_array",
587
+ "unnest",
588
+ "upper",
589
+ "value_of",
590
+ "var_pop",
591
+ "var_samp",
592
+ "width_bucket"
593
+ ];
594
+ const POSSIBLE_WITHOUT_PARENS = [
595
+ "current_catalog",
596
+ "current_date",
597
+ "current_default_transform_group",
598
+ "current_path",
599
+ "current_role",
600
+ "current_schema",
601
+ "current_transform_group_for_type",
602
+ "current_user",
603
+ "session_user",
604
+ "system_time",
605
+ "system_user",
606
+ "current_time",
607
+ "localtime",
608
+ "current_timestamp",
609
+ "localtimestamp"
610
+ ];
611
+ const COMBOS = [
612
+ "create table",
613
+ "insert into",
614
+ "primary key",
615
+ "foreign key",
616
+ "not null",
617
+ "alter table",
618
+ "add constraint",
619
+ "grouping sets",
620
+ "on overflow",
621
+ "character set",
622
+ "respect nulls",
623
+ "ignore nulls",
624
+ "nulls first",
625
+ "nulls last",
626
+ "depth first",
627
+ "breadth first"
628
+ ];
629
+ const FUNCTIONS = RESERVED_FUNCTIONS;
630
+ const KEYWORDS3 = [
631
+ ...RESERVED_WORDS,
632
+ ...NON_RESERVED_WORDS
633
+ ].filter((keyword) => {
634
+ return !RESERVED_FUNCTIONS.includes(keyword);
635
+ });
636
+ const VARIABLE = {
637
+ scope: "variable",
638
+ match: /@[a-z0-9][a-z0-9_]*/
639
+ };
640
+ const OPERATOR = {
641
+ scope: "operator",
642
+ match: /[-+*/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?/,
643
+ relevance: 0
644
+ };
645
+ const FUNCTION_CALL = {
646
+ match: regex.concat(/\b/, regex.either(...FUNCTIONS), /\s*\(/),
647
+ relevance: 0,
648
+ keywords: { built_in: FUNCTIONS }
649
+ };
650
+ function kws_to_regex(list) {
651
+ return regex.concat(
652
+ /\b/,
653
+ regex.either(...list.map((kw) => {
654
+ return kw.replace(/\s+/, "\\s+");
655
+ })),
656
+ /\b/
657
+ );
658
+ }
659
+ const MULTI_WORD_KEYWORDS = {
660
+ scope: "keyword",
661
+ match: kws_to_regex(COMBOS),
662
+ relevance: 0
663
+ };
664
+ function reduceRelevancy(list, {
665
+ exceptions,
666
+ when
667
+ } = {}) {
668
+ const qualifyFn = when;
669
+ exceptions = exceptions || [];
670
+ return list.map((item) => {
671
+ if (item.match(/\|\d+$/) || exceptions.includes(item)) {
672
+ return item;
673
+ } else if (qualifyFn(item)) {
674
+ return `${item}|0`;
675
+ } else {
676
+ return item;
677
+ }
678
+ });
679
+ }
680
+ return {
681
+ name: "SQL",
682
+ case_insensitive: true,
683
+ // does not include {} or HTML tags `</`
684
+ illegal: /[{}]|<\//,
685
+ keywords: {
686
+ $pattern: /\b[\w\.]+/,
687
+ keyword: reduceRelevancy(KEYWORDS3, { when: (x) => x.length < 3 }),
688
+ literal: LITERALS3,
689
+ type: TYPES3,
690
+ built_in: POSSIBLE_WITHOUT_PARENS
691
+ },
692
+ contains: [
693
+ {
694
+ scope: "type",
695
+ match: kws_to_regex(MULTI_WORD_TYPES)
696
+ },
697
+ MULTI_WORD_KEYWORDS,
698
+ FUNCTION_CALL,
699
+ VARIABLE,
700
+ STRING,
701
+ QUOTED_IDENTIFIER,
702
+ hljs.C_NUMBER_MODE,
703
+ hljs.C_BLOCK_COMMENT_MODE,
704
+ COMMENT_MODE,
705
+ OPERATOR
706
+ ]
707
+ };
708
+ }
709
+
710
+ // node_modules/highlight.js/es/languages/typescript.js
711
+ var IDENT_RE = "[A-Za-z$_][0-9A-Za-z$_]*";
712
+ var KEYWORDS = [
713
+ "as",
714
+ // for exports
715
+ "in",
716
+ "of",
717
+ "if",
718
+ "for",
719
+ "while",
720
+ "finally",
721
+ "var",
722
+ "new",
723
+ "function",
724
+ "do",
725
+ "return",
726
+ "void",
727
+ "else",
728
+ "break",
729
+ "catch",
730
+ "instanceof",
731
+ "with",
732
+ "throw",
733
+ "case",
734
+ "default",
735
+ "try",
736
+ "switch",
737
+ "continue",
738
+ "typeof",
739
+ "delete",
740
+ "let",
741
+ "yield",
742
+ "const",
743
+ "class",
744
+ // JS handles these with a special rule
745
+ // "get",
746
+ // "set",
747
+ "debugger",
748
+ "async",
749
+ "await",
750
+ "static",
751
+ "import",
752
+ "from",
753
+ "export",
754
+ "extends",
755
+ // It's reached stage 3, which is "recommended for implementation":
756
+ "using"
757
+ ];
758
+ var LITERALS = [
759
+ "true",
760
+ "false",
761
+ "null",
762
+ "undefined",
763
+ "NaN",
764
+ "Infinity"
765
+ ];
766
+ var TYPES = [
767
+ // Fundamental objects
768
+ "Object",
769
+ "Function",
770
+ "Boolean",
771
+ "Symbol",
772
+ // numbers and dates
773
+ "Math",
774
+ "Date",
775
+ "Number",
776
+ "BigInt",
777
+ // text
778
+ "String",
779
+ "RegExp",
780
+ // Indexed collections
781
+ "Array",
782
+ "Float32Array",
783
+ "Float64Array",
784
+ "Int8Array",
785
+ "Uint8Array",
786
+ "Uint8ClampedArray",
787
+ "Int16Array",
788
+ "Int32Array",
789
+ "Uint16Array",
790
+ "Uint32Array",
791
+ "BigInt64Array",
792
+ "BigUint64Array",
793
+ // Keyed collections
794
+ "Set",
795
+ "Map",
796
+ "WeakSet",
797
+ "WeakMap",
798
+ // Structured data
799
+ "ArrayBuffer",
800
+ "SharedArrayBuffer",
801
+ "Atomics",
802
+ "DataView",
803
+ "JSON",
804
+ // Control abstraction objects
805
+ "Promise",
806
+ "Generator",
807
+ "GeneratorFunction",
808
+ "AsyncFunction",
809
+ // Reflection
810
+ "Reflect",
811
+ "Proxy",
812
+ // Internationalization
813
+ "Intl",
814
+ // WebAssembly
815
+ "WebAssembly"
816
+ ];
817
+ var ERROR_TYPES = [
818
+ "Error",
819
+ "EvalError",
820
+ "InternalError",
821
+ "RangeError",
822
+ "ReferenceError",
823
+ "SyntaxError",
824
+ "TypeError",
825
+ "URIError"
826
+ ];
827
+ var BUILT_IN_GLOBALS = [
828
+ "setInterval",
829
+ "setTimeout",
830
+ "clearInterval",
831
+ "clearTimeout",
832
+ "require",
833
+ "exports",
834
+ "eval",
835
+ "isFinite",
836
+ "isNaN",
837
+ "parseFloat",
838
+ "parseInt",
839
+ "decodeURI",
840
+ "decodeURIComponent",
841
+ "encodeURI",
842
+ "encodeURIComponent",
843
+ "escape",
844
+ "unescape"
845
+ ];
846
+ var BUILT_IN_VARIABLES = [
847
+ "arguments",
848
+ "this",
849
+ "super",
850
+ "console",
851
+ "window",
852
+ "document",
853
+ "localStorage",
854
+ "sessionStorage",
855
+ "module",
856
+ "self",
857
+ "global"
858
+ // Node.js
859
+ ];
860
+ var BUILT_INS = [].concat(
861
+ BUILT_IN_GLOBALS,
862
+ TYPES,
863
+ ERROR_TYPES
864
+ );
865
+ function javascript(hljs) {
866
+ const regex = hljs.regex;
867
+ const hasClosingTag = (match, { after }) => {
868
+ const tag = "</" + match[0].slice(1);
869
+ const pos = match.input.indexOf(tag, after);
870
+ return pos !== -1;
871
+ };
872
+ const IDENT_RE$1 = IDENT_RE;
873
+ const FRAGMENT = {
874
+ begin: "<>",
875
+ end: "</>"
876
+ };
877
+ const XML_SELF_CLOSING = /<[A-Za-z0-9\\._:-]+\s*\/>/;
878
+ const XML_TAG = {
879
+ begin: /<[A-Za-z0-9\\._:-]+/,
880
+ end: /\/[A-Za-z0-9\\._:-]+>|\/>/,
881
+ /**
882
+ * @param {RegExpMatchArray} match
883
+ * @param {CallbackResponse} response
884
+ */
885
+ isTrulyOpeningTag: (match, response) => {
886
+ const afterMatchIndex = match[0].length + match.index;
887
+ const nextChar = match.input[afterMatchIndex];
888
+ if (
889
+ // HTML should not include another raw `<` inside a tag
890
+ // nested type?
891
+ // `<Array<Array<number>>`, etc.
892
+ nextChar === "<" || // the , gives away that this is not HTML
893
+ // `<T, A extends keyof T, V>`
894
+ nextChar === ","
895
+ ) {
896
+ response.ignoreMatch();
897
+ return;
898
+ }
899
+ if (nextChar === ">") {
900
+ if (!hasClosingTag(match, { after: afterMatchIndex })) {
901
+ response.ignoreMatch();
902
+ }
903
+ }
904
+ let m;
905
+ const afterMatch = match.input.substring(afterMatchIndex);
906
+ if (m = afterMatch.match(/^\s*=/)) {
907
+ response.ignoreMatch();
908
+ return;
909
+ }
910
+ if (m = afterMatch.match(/^\s+extends\s+/)) {
911
+ if (m.index === 0) {
912
+ response.ignoreMatch();
913
+ return;
914
+ }
915
+ }
916
+ }
917
+ };
918
+ const KEYWORDS$1 = {
919
+ $pattern: IDENT_RE,
920
+ keyword: KEYWORDS,
921
+ literal: LITERALS,
922
+ built_in: BUILT_INS,
923
+ "variable.language": BUILT_IN_VARIABLES
924
+ };
925
+ const decimalDigits2 = "[0-9](_?[0-9])*";
926
+ const frac2 = `\\.(${decimalDigits2})`;
927
+ const decimalInteger = `0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*`;
928
+ const NUMBER = {
929
+ className: "number",
930
+ variants: [
931
+ // DecimalLiteral
932
+ { begin: `(\\b(${decimalInteger})((${frac2})|\\.)?|(${frac2}))[eE][+-]?(${decimalDigits2})\\b` },
933
+ { begin: `\\b(${decimalInteger})\\b((${frac2})\\b|\\.)?|(${frac2})\\b` },
934
+ // DecimalBigIntegerLiteral
935
+ { begin: `\\b(0|[1-9](_?[0-9])*)n\\b` },
936
+ // NonDecimalIntegerLiteral
937
+ { begin: "\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b" },
938
+ { begin: "\\b0[bB][0-1](_?[0-1])*n?\\b" },
939
+ { begin: "\\b0[oO][0-7](_?[0-7])*n?\\b" },
940
+ // LegacyOctalIntegerLiteral (does not include underscore separators)
941
+ // https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals
942
+ { begin: "\\b0[0-7]+n?\\b" }
943
+ ],
944
+ relevance: 0
945
+ };
946
+ const SUBST = {
947
+ className: "subst",
948
+ begin: "\\$\\{",
949
+ end: "\\}",
950
+ keywords: KEYWORDS$1,
951
+ contains: []
952
+ // defined later
953
+ };
954
+ const HTML_TEMPLATE = {
955
+ begin: ".?html`",
956
+ end: "",
957
+ starts: {
958
+ end: "`",
959
+ returnEnd: false,
960
+ contains: [
961
+ hljs.BACKSLASH_ESCAPE,
962
+ SUBST
963
+ ],
964
+ subLanguage: "xml"
965
+ }
966
+ };
967
+ const CSS_TEMPLATE = {
968
+ begin: ".?css`",
969
+ end: "",
970
+ starts: {
971
+ end: "`",
972
+ returnEnd: false,
973
+ contains: [
974
+ hljs.BACKSLASH_ESCAPE,
975
+ SUBST
976
+ ],
977
+ subLanguage: "css"
978
+ }
979
+ };
980
+ const GRAPHQL_TEMPLATE = {
981
+ begin: ".?gql`",
982
+ end: "",
983
+ starts: {
984
+ end: "`",
985
+ returnEnd: false,
986
+ contains: [
987
+ hljs.BACKSLASH_ESCAPE,
988
+ SUBST
989
+ ],
990
+ subLanguage: "graphql"
991
+ }
992
+ };
993
+ const TEMPLATE_STRING = {
994
+ className: "string",
995
+ begin: "`",
996
+ end: "`",
997
+ contains: [
998
+ hljs.BACKSLASH_ESCAPE,
999
+ SUBST
1000
+ ]
1001
+ };
1002
+ const JSDOC_COMMENT = hljs.COMMENT(
1003
+ /\/\*\*(?!\/)/,
1004
+ "\\*/",
1005
+ {
1006
+ relevance: 0,
1007
+ contains: [
1008
+ {
1009
+ begin: "(?=@[A-Za-z]+)",
1010
+ relevance: 0,
1011
+ contains: [
1012
+ {
1013
+ className: "doctag",
1014
+ begin: "@[A-Za-z]+"
1015
+ },
1016
+ {
1017
+ className: "type",
1018
+ begin: "\\{",
1019
+ end: "\\}",
1020
+ excludeEnd: true,
1021
+ excludeBegin: true,
1022
+ relevance: 0
1023
+ },
1024
+ {
1025
+ className: "variable",
1026
+ begin: IDENT_RE$1 + "(?=\\s*(-)|$)",
1027
+ endsParent: true,
1028
+ relevance: 0
1029
+ },
1030
+ // eat spaces (not newlines) so we can find
1031
+ // types or variables
1032
+ {
1033
+ begin: /(?=[^\n])\s/,
1034
+ relevance: 0
1035
+ }
1036
+ ]
1037
+ }
1038
+ ]
1039
+ }
1040
+ );
1041
+ const COMMENT = {
1042
+ className: "comment",
1043
+ variants: [
1044
+ JSDOC_COMMENT,
1045
+ hljs.C_BLOCK_COMMENT_MODE,
1046
+ hljs.C_LINE_COMMENT_MODE
1047
+ ]
1048
+ };
1049
+ const SUBST_INTERNALS = [
1050
+ hljs.APOS_STRING_MODE,
1051
+ hljs.QUOTE_STRING_MODE,
1052
+ HTML_TEMPLATE,
1053
+ CSS_TEMPLATE,
1054
+ GRAPHQL_TEMPLATE,
1055
+ TEMPLATE_STRING,
1056
+ // Skip numbers when they are part of a variable name
1057
+ { match: /\$\d+/ },
1058
+ NUMBER
1059
+ // This is intentional:
1060
+ // See https://github.com/highlightjs/highlight.js/issues/3288
1061
+ // hljs.REGEXP_MODE
1062
+ ];
1063
+ SUBST.contains = SUBST_INTERNALS.concat({
1064
+ // we need to pair up {} inside our subst to prevent
1065
+ // it from ending too early by matching another }
1066
+ begin: /\{/,
1067
+ end: /\}/,
1068
+ keywords: KEYWORDS$1,
1069
+ contains: [
1070
+ "self"
1071
+ ].concat(SUBST_INTERNALS)
1072
+ });
1073
+ const SUBST_AND_COMMENTS = [].concat(COMMENT, SUBST.contains);
1074
+ const PARAMS_CONTAINS = SUBST_AND_COMMENTS.concat([
1075
+ // eat recursive parens in sub expressions
1076
+ {
1077
+ begin: /(\s*)\(/,
1078
+ end: /\)/,
1079
+ keywords: KEYWORDS$1,
1080
+ contains: ["self"].concat(SUBST_AND_COMMENTS)
1081
+ }
1082
+ ]);
1083
+ const PARAMS = {
1084
+ className: "params",
1085
+ // convert this to negative lookbehind in v12
1086
+ begin: /(\s*)\(/,
1087
+ // to match the parms with
1088
+ end: /\)/,
1089
+ excludeBegin: true,
1090
+ excludeEnd: true,
1091
+ keywords: KEYWORDS$1,
1092
+ contains: PARAMS_CONTAINS
1093
+ };
1094
+ const CLASS_OR_EXTENDS = {
1095
+ variants: [
1096
+ // class Car extends vehicle
1097
+ {
1098
+ match: [
1099
+ /class/,
1100
+ /\s+/,
1101
+ IDENT_RE$1,
1102
+ /\s+/,
1103
+ /extends/,
1104
+ /\s+/,
1105
+ regex.concat(IDENT_RE$1, "(", regex.concat(/\./, IDENT_RE$1), ")*")
1106
+ ],
1107
+ scope: {
1108
+ 1: "keyword",
1109
+ 3: "title.class",
1110
+ 5: "keyword",
1111
+ 7: "title.class.inherited"
1112
+ }
1113
+ },
1114
+ // class Car
1115
+ {
1116
+ match: [
1117
+ /class/,
1118
+ /\s+/,
1119
+ IDENT_RE$1
1120
+ ],
1121
+ scope: {
1122
+ 1: "keyword",
1123
+ 3: "title.class"
1124
+ }
1125
+ }
1126
+ ]
1127
+ };
1128
+ const CLASS_REFERENCE = {
1129
+ relevance: 0,
1130
+ match: regex.either(
1131
+ // Hard coded exceptions
1132
+ /\bJSON/,
1133
+ // Float32Array, OutT
1134
+ /\b[A-Z][a-z]+([A-Z][a-z]*|\d)*/,
1135
+ // CSSFactory, CSSFactoryT
1136
+ /\b[A-Z]{2,}([A-Z][a-z]+|\d)+([A-Z][a-z]*)*/,
1137
+ // FPs, FPsT
1138
+ /\b[A-Z]{2,}[a-z]+([A-Z][a-z]+|\d)*([A-Z][a-z]*)*/
1139
+ // P
1140
+ // single letters are not highlighted
1141
+ // BLAH
1142
+ // this will be flagged as a UPPER_CASE_CONSTANT instead
1143
+ ),
1144
+ className: "title.class",
1145
+ keywords: {
1146
+ _: [
1147
+ // se we still get relevance credit for JS library classes
1148
+ ...TYPES,
1149
+ ...ERROR_TYPES
1150
+ ]
1151
+ }
1152
+ };
1153
+ const USE_STRICT = {
1154
+ label: "use_strict",
1155
+ className: "meta",
1156
+ relevance: 10,
1157
+ begin: /^\s*['"]use (strict|asm)['"]/
1158
+ };
1159
+ const FUNCTION_DEFINITION = {
1160
+ variants: [
1161
+ {
1162
+ match: [
1163
+ /function/,
1164
+ /\s+/,
1165
+ IDENT_RE$1,
1166
+ /(?=\s*\()/
1167
+ ]
1168
+ },
1169
+ // anonymous function
1170
+ {
1171
+ match: [
1172
+ /function/,
1173
+ /\s*(?=\()/
1174
+ ]
1175
+ }
1176
+ ],
1177
+ className: {
1178
+ 1: "keyword",
1179
+ 3: "title.function"
1180
+ },
1181
+ label: "func.def",
1182
+ contains: [PARAMS],
1183
+ illegal: /%/
1184
+ };
1185
+ const UPPER_CASE_CONSTANT = {
1186
+ relevance: 0,
1187
+ match: /\b[A-Z][A-Z_0-9]+\b/,
1188
+ className: "variable.constant"
1189
+ };
1190
+ function noneOf(list) {
1191
+ return regex.concat("(?!", list.join("|"), ")");
1192
+ }
1193
+ const FUNCTION_CALL = {
1194
+ match: regex.concat(
1195
+ /\b/,
1196
+ noneOf([
1197
+ ...BUILT_IN_GLOBALS,
1198
+ "super",
1199
+ "import",
1200
+ "await"
1201
+ ].map((x) => `${x}\\s*\\(`)),
1202
+ IDENT_RE$1,
1203
+ regex.lookahead(/\s*\(/)
1204
+ ),
1205
+ className: "title.function",
1206
+ relevance: 0
1207
+ };
1208
+ const PROPERTY_ACCESS = {
1209
+ begin: regex.concat(/\./, regex.lookahead(
1210
+ regex.concat(IDENT_RE$1, /(?![0-9A-Za-z$_(])/)
1211
+ )),
1212
+ end: IDENT_RE$1,
1213
+ excludeBegin: true,
1214
+ keywords: "prototype",
1215
+ className: "property",
1216
+ relevance: 0
1217
+ };
1218
+ const GETTER_OR_SETTER = {
1219
+ match: [
1220
+ /get|set/,
1221
+ /\s+/,
1222
+ IDENT_RE$1,
1223
+ /(?=\()/
1224
+ ],
1225
+ className: {
1226
+ 1: "keyword",
1227
+ 3: "title.function"
1228
+ },
1229
+ contains: [
1230
+ {
1231
+ // eat to avoid empty params
1232
+ begin: /\(\)/
1233
+ },
1234
+ PARAMS
1235
+ ]
1236
+ };
1237
+ const FUNC_LEAD_IN_RE = "(\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)|" + hljs.UNDERSCORE_IDENT_RE + ")\\s*=>";
1238
+ const FUNCTION_VARIABLE = {
1239
+ match: [
1240
+ /const|var|let/,
1241
+ /\s+/,
1242
+ IDENT_RE$1,
1243
+ /\s*/,
1244
+ /=\s*/,
1245
+ /(async\s*)?/,
1246
+ // async is optional
1247
+ regex.lookahead(FUNC_LEAD_IN_RE)
1248
+ ],
1249
+ keywords: "async",
1250
+ className: {
1251
+ 1: "keyword",
1252
+ 3: "title.function"
1253
+ },
1254
+ contains: [
1255
+ PARAMS
1256
+ ]
1257
+ };
1258
+ return {
1259
+ name: "JavaScript",
1260
+ aliases: ["js", "jsx", "mjs", "cjs"],
1261
+ keywords: KEYWORDS$1,
1262
+ // this will be extended by TypeScript
1263
+ exports: { PARAMS_CONTAINS, CLASS_REFERENCE },
1264
+ illegal: /#(?![$_A-Za-z])/,
1265
+ contains: [
1266
+ hljs.SHEBANG({
1267
+ label: "shebang",
1268
+ binary: "node",
1269
+ relevance: 5
1270
+ }),
1271
+ USE_STRICT,
1272
+ hljs.APOS_STRING_MODE,
1273
+ hljs.QUOTE_STRING_MODE,
1274
+ HTML_TEMPLATE,
1275
+ CSS_TEMPLATE,
1276
+ GRAPHQL_TEMPLATE,
1277
+ TEMPLATE_STRING,
1278
+ COMMENT,
1279
+ // Skip numbers when they are part of a variable name
1280
+ { match: /\$\d+/ },
1281
+ NUMBER,
1282
+ CLASS_REFERENCE,
1283
+ {
1284
+ scope: "attr",
1285
+ match: IDENT_RE$1 + regex.lookahead(":"),
1286
+ relevance: 0
1287
+ },
1288
+ FUNCTION_VARIABLE,
1289
+ {
1290
+ // "value" container
1291
+ begin: "(" + hljs.RE_STARTERS_RE + "|\\b(case|return|throw)\\b)\\s*",
1292
+ keywords: "return throw case",
1293
+ relevance: 0,
1294
+ contains: [
1295
+ COMMENT,
1296
+ hljs.REGEXP_MODE,
1297
+ {
1298
+ className: "function",
1299
+ // we have to count the parens to make sure we actually have the
1300
+ // correct bounding ( ) before the =>. There could be any number of
1301
+ // sub-expressions inside also surrounded by parens.
1302
+ begin: FUNC_LEAD_IN_RE,
1303
+ returnBegin: true,
1304
+ end: "\\s*=>",
1305
+ contains: [
1306
+ {
1307
+ className: "params",
1308
+ variants: [
1309
+ {
1310
+ begin: hljs.UNDERSCORE_IDENT_RE,
1311
+ relevance: 0
1312
+ },
1313
+ {
1314
+ className: null,
1315
+ begin: /\(\s*\)/,
1316
+ skip: true
1317
+ },
1318
+ {
1319
+ begin: /(\s*)\(/,
1320
+ end: /\)/,
1321
+ excludeBegin: true,
1322
+ excludeEnd: true,
1323
+ keywords: KEYWORDS$1,
1324
+ contains: PARAMS_CONTAINS
1325
+ }
1326
+ ]
1327
+ }
1328
+ ]
1329
+ },
1330
+ {
1331
+ // could be a comma delimited list of params to a function call
1332
+ begin: /,/,
1333
+ relevance: 0
1334
+ },
1335
+ {
1336
+ match: /\s+/,
1337
+ relevance: 0
1338
+ },
1339
+ {
1340
+ // JSX
1341
+ variants: [
1342
+ { begin: FRAGMENT.begin, end: FRAGMENT.end },
1343
+ { match: XML_SELF_CLOSING },
1344
+ {
1345
+ begin: XML_TAG.begin,
1346
+ // we carefully check the opening tag to see if it truly
1347
+ // is a tag and not a false positive
1348
+ "on:begin": XML_TAG.isTrulyOpeningTag,
1349
+ end: XML_TAG.end
1350
+ }
1351
+ ],
1352
+ subLanguage: "xml",
1353
+ contains: [
1354
+ {
1355
+ begin: XML_TAG.begin,
1356
+ end: XML_TAG.end,
1357
+ skip: true,
1358
+ contains: ["self"]
1359
+ }
1360
+ ]
1361
+ }
1362
+ ]
1363
+ },
1364
+ FUNCTION_DEFINITION,
1365
+ {
1366
+ // prevent this from getting swallowed up by function
1367
+ // since they appear "function like"
1368
+ beginKeywords: "while if switch catch for"
1369
+ },
1370
+ {
1371
+ // we have to count the parens to make sure we actually have the correct
1372
+ // bounding ( ). There could be any number of sub-expressions inside
1373
+ // also surrounded by parens.
1374
+ begin: "\\b(?!function)" + hljs.UNDERSCORE_IDENT_RE + "\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)\\s*\\{",
1375
+ // end parens
1376
+ returnBegin: true,
1377
+ label: "func.def",
1378
+ contains: [
1379
+ PARAMS,
1380
+ hljs.inherit(hljs.TITLE_MODE, { begin: IDENT_RE$1, className: "title.function" })
1381
+ ]
1382
+ },
1383
+ // catch ... so it won't trigger the property rule below
1384
+ {
1385
+ match: /\.\.\./,
1386
+ relevance: 0
1387
+ },
1388
+ PROPERTY_ACCESS,
1389
+ // hack: prevents detection of keywords in some circumstances
1390
+ // .keyword()
1391
+ // $keyword = x
1392
+ {
1393
+ match: "\\$" + IDENT_RE$1,
1394
+ relevance: 0
1395
+ },
1396
+ {
1397
+ match: [/\bconstructor(?=\s*\()/],
1398
+ className: { 1: "title.function" },
1399
+ contains: [PARAMS]
1400
+ },
1401
+ FUNCTION_CALL,
1402
+ UPPER_CASE_CONSTANT,
1403
+ CLASS_OR_EXTENDS,
1404
+ GETTER_OR_SETTER,
1405
+ {
1406
+ match: /\$[(.]/
1407
+ // relevance booster for a pattern common to JS libs: `$(something)` and `$.something`
1408
+ }
1409
+ ]
1410
+ };
1411
+ }
1412
+ function typescript(hljs) {
1413
+ const regex = hljs.regex;
1414
+ const tsLanguage = javascript(hljs);
1415
+ const IDENT_RE$1 = IDENT_RE;
1416
+ const TYPES3 = [
1417
+ "any",
1418
+ "void",
1419
+ "number",
1420
+ "boolean",
1421
+ "string",
1422
+ "object",
1423
+ "never",
1424
+ "symbol",
1425
+ "bigint",
1426
+ "unknown"
1427
+ ];
1428
+ const NAMESPACE = {
1429
+ begin: [
1430
+ /namespace/,
1431
+ /\s+/,
1432
+ hljs.IDENT_RE
1433
+ ],
1434
+ beginScope: {
1435
+ 1: "keyword",
1436
+ 3: "title.class"
1437
+ }
1438
+ };
1439
+ const INTERFACE = {
1440
+ beginKeywords: "interface",
1441
+ end: /\{/,
1442
+ excludeEnd: true,
1443
+ keywords: {
1444
+ keyword: "interface extends",
1445
+ built_in: TYPES3
1446
+ },
1447
+ contains: [tsLanguage.exports.CLASS_REFERENCE]
1448
+ };
1449
+ const USE_STRICT = {
1450
+ className: "meta",
1451
+ relevance: 10,
1452
+ begin: /^\s*['"]use strict['"]/
1453
+ };
1454
+ const TS_SPECIFIC_KEYWORDS = [
1455
+ "type",
1456
+ // "namespace",
1457
+ "interface",
1458
+ "public",
1459
+ "private",
1460
+ "protected",
1461
+ "implements",
1462
+ "declare",
1463
+ "abstract",
1464
+ "readonly",
1465
+ "enum",
1466
+ "override",
1467
+ "satisfies"
1468
+ ];
1469
+ const KEYWORDS$1 = {
1470
+ $pattern: IDENT_RE,
1471
+ keyword: KEYWORDS.concat(TS_SPECIFIC_KEYWORDS),
1472
+ literal: LITERALS,
1473
+ built_in: BUILT_INS.concat(TYPES3),
1474
+ "variable.language": BUILT_IN_VARIABLES
1475
+ };
1476
+ const DECORATOR = {
1477
+ className: "meta",
1478
+ begin: "@" + IDENT_RE$1
1479
+ };
1480
+ const swapMode = (mode, label, replacement) => {
1481
+ const indx = mode.contains.findIndex((m) => m.label === label);
1482
+ if (indx === -1) {
1483
+ throw new Error("can not find mode to replace");
1484
+ }
1485
+ mode.contains.splice(indx, 1, replacement);
1486
+ };
1487
+ Object.assign(tsLanguage.keywords, KEYWORDS$1);
1488
+ tsLanguage.exports.PARAMS_CONTAINS.push(DECORATOR);
1489
+ const ATTRIBUTE_HIGHLIGHT = tsLanguage.contains.find((c) => c.scope === "attr");
1490
+ const OPTIONAL_KEY_OR_ARGUMENT = Object.assign(
1491
+ {},
1492
+ ATTRIBUTE_HIGHLIGHT,
1493
+ { match: regex.concat(IDENT_RE$1, regex.lookahead(/\s*\?:/)) }
1494
+ );
1495
+ tsLanguage.exports.PARAMS_CONTAINS.push([
1496
+ tsLanguage.exports.CLASS_REFERENCE,
1497
+ // class reference for highlighting the params types
1498
+ ATTRIBUTE_HIGHLIGHT,
1499
+ // highlight the params key
1500
+ OPTIONAL_KEY_OR_ARGUMENT
1501
+ // Added for optional property assignment highlighting
1502
+ ]);
1503
+ tsLanguage.contains = tsLanguage.contains.concat([
1504
+ DECORATOR,
1505
+ NAMESPACE,
1506
+ INTERFACE,
1507
+ OPTIONAL_KEY_OR_ARGUMENT
1508
+ // Added for optional property assignment highlighting
1509
+ ]);
1510
+ swapMode(tsLanguage, "shebang", hljs.SHEBANG());
1511
+ swapMode(tsLanguage, "use_strict", USE_STRICT);
1512
+ const functionDeclaration = tsLanguage.contains.find((m) => m.label === "func.def");
1513
+ functionDeclaration.relevance = 0;
1514
+ Object.assign(tsLanguage, {
1515
+ name: "TypeScript",
1516
+ aliases: [
1517
+ "ts",
1518
+ "tsx",
1519
+ "mts",
1520
+ "cts"
1521
+ ]
1522
+ });
1523
+ return tsLanguage;
1524
+ }
1525
+
1526
+ // node_modules/highlight.js/es/languages/javascript.js
1527
+ var IDENT_RE2 = "[A-Za-z$_][0-9A-Za-z$_]*";
1528
+ var KEYWORDS2 = [
1529
+ "as",
1530
+ // for exports
1531
+ "in",
1532
+ "of",
1533
+ "if",
1534
+ "for",
1535
+ "while",
1536
+ "finally",
1537
+ "var",
1538
+ "new",
1539
+ "function",
1540
+ "do",
1541
+ "return",
1542
+ "void",
1543
+ "else",
1544
+ "break",
1545
+ "catch",
1546
+ "instanceof",
1547
+ "with",
1548
+ "throw",
1549
+ "case",
1550
+ "default",
1551
+ "try",
1552
+ "switch",
1553
+ "continue",
1554
+ "typeof",
1555
+ "delete",
1556
+ "let",
1557
+ "yield",
1558
+ "const",
1559
+ "class",
1560
+ // JS handles these with a special rule
1561
+ // "get",
1562
+ // "set",
1563
+ "debugger",
1564
+ "async",
1565
+ "await",
1566
+ "static",
1567
+ "import",
1568
+ "from",
1569
+ "export",
1570
+ "extends",
1571
+ // It's reached stage 3, which is "recommended for implementation":
1572
+ "using"
1573
+ ];
1574
+ var LITERALS2 = [
1575
+ "true",
1576
+ "false",
1577
+ "null",
1578
+ "undefined",
1579
+ "NaN",
1580
+ "Infinity"
1581
+ ];
1582
+ var TYPES2 = [
1583
+ // Fundamental objects
1584
+ "Object",
1585
+ "Function",
1586
+ "Boolean",
1587
+ "Symbol",
1588
+ // numbers and dates
1589
+ "Math",
1590
+ "Date",
1591
+ "Number",
1592
+ "BigInt",
1593
+ // text
1594
+ "String",
1595
+ "RegExp",
1596
+ // Indexed collections
1597
+ "Array",
1598
+ "Float32Array",
1599
+ "Float64Array",
1600
+ "Int8Array",
1601
+ "Uint8Array",
1602
+ "Uint8ClampedArray",
1603
+ "Int16Array",
1604
+ "Int32Array",
1605
+ "Uint16Array",
1606
+ "Uint32Array",
1607
+ "BigInt64Array",
1608
+ "BigUint64Array",
1609
+ // Keyed collections
1610
+ "Set",
1611
+ "Map",
1612
+ "WeakSet",
1613
+ "WeakMap",
1614
+ // Structured data
1615
+ "ArrayBuffer",
1616
+ "SharedArrayBuffer",
1617
+ "Atomics",
1618
+ "DataView",
1619
+ "JSON",
1620
+ // Control abstraction objects
1621
+ "Promise",
1622
+ "Generator",
1623
+ "GeneratorFunction",
1624
+ "AsyncFunction",
1625
+ // Reflection
1626
+ "Reflect",
1627
+ "Proxy",
1628
+ // Internationalization
1629
+ "Intl",
1630
+ // WebAssembly
1631
+ "WebAssembly"
1632
+ ];
1633
+ var ERROR_TYPES2 = [
1634
+ "Error",
1635
+ "EvalError",
1636
+ "InternalError",
1637
+ "RangeError",
1638
+ "ReferenceError",
1639
+ "SyntaxError",
1640
+ "TypeError",
1641
+ "URIError"
1642
+ ];
1643
+ var BUILT_IN_GLOBALS2 = [
1644
+ "setInterval",
1645
+ "setTimeout",
1646
+ "clearInterval",
1647
+ "clearTimeout",
1648
+ "require",
1649
+ "exports",
1650
+ "eval",
1651
+ "isFinite",
1652
+ "isNaN",
1653
+ "parseFloat",
1654
+ "parseInt",
1655
+ "decodeURI",
1656
+ "decodeURIComponent",
1657
+ "encodeURI",
1658
+ "encodeURIComponent",
1659
+ "escape",
1660
+ "unescape"
1661
+ ];
1662
+ var BUILT_IN_VARIABLES2 = [
1663
+ "arguments",
1664
+ "this",
1665
+ "super",
1666
+ "console",
1667
+ "window",
1668
+ "document",
1669
+ "localStorage",
1670
+ "sessionStorage",
1671
+ "module",
1672
+ "self",
1673
+ "global"
1674
+ // Node.js
1675
+ ];
1676
+ var BUILT_INS2 = [].concat(
1677
+ BUILT_IN_GLOBALS2,
1678
+ TYPES2,
1679
+ ERROR_TYPES2
1680
+ );
1681
+ function javascript2(hljs) {
1682
+ const regex = hljs.regex;
1683
+ const hasClosingTag = (match, { after }) => {
1684
+ const tag = "</" + match[0].slice(1);
1685
+ const pos = match.input.indexOf(tag, after);
1686
+ return pos !== -1;
1687
+ };
1688
+ const IDENT_RE$1 = IDENT_RE2;
1689
+ const FRAGMENT = {
1690
+ begin: "<>",
1691
+ end: "</>"
1692
+ };
1693
+ const XML_SELF_CLOSING = /<[A-Za-z0-9\\._:-]+\s*\/>/;
1694
+ const XML_TAG = {
1695
+ begin: /<[A-Za-z0-9\\._:-]+/,
1696
+ end: /\/[A-Za-z0-9\\._:-]+>|\/>/,
1697
+ /**
1698
+ * @param {RegExpMatchArray} match
1699
+ * @param {CallbackResponse} response
1700
+ */
1701
+ isTrulyOpeningTag: (match, response) => {
1702
+ const afterMatchIndex = match[0].length + match.index;
1703
+ const nextChar = match.input[afterMatchIndex];
1704
+ if (
1705
+ // HTML should not include another raw `<` inside a tag
1706
+ // nested type?
1707
+ // `<Array<Array<number>>`, etc.
1708
+ nextChar === "<" || // the , gives away that this is not HTML
1709
+ // `<T, A extends keyof T, V>`
1710
+ nextChar === ","
1711
+ ) {
1712
+ response.ignoreMatch();
1713
+ return;
1714
+ }
1715
+ if (nextChar === ">") {
1716
+ if (!hasClosingTag(match, { after: afterMatchIndex })) {
1717
+ response.ignoreMatch();
1718
+ }
1719
+ }
1720
+ let m;
1721
+ const afterMatch = match.input.substring(afterMatchIndex);
1722
+ if (m = afterMatch.match(/^\s*=/)) {
1723
+ response.ignoreMatch();
1724
+ return;
1725
+ }
1726
+ if (m = afterMatch.match(/^\s+extends\s+/)) {
1727
+ if (m.index === 0) {
1728
+ response.ignoreMatch();
1729
+ return;
1730
+ }
1731
+ }
1732
+ }
1733
+ };
1734
+ const KEYWORDS$1 = {
1735
+ $pattern: IDENT_RE2,
1736
+ keyword: KEYWORDS2,
1737
+ literal: LITERALS2,
1738
+ built_in: BUILT_INS2,
1739
+ "variable.language": BUILT_IN_VARIABLES2
1740
+ };
1741
+ const decimalDigits2 = "[0-9](_?[0-9])*";
1742
+ const frac2 = `\\.(${decimalDigits2})`;
1743
+ const decimalInteger = `0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*`;
1744
+ const NUMBER = {
1745
+ className: "number",
1746
+ variants: [
1747
+ // DecimalLiteral
1748
+ { begin: `(\\b(${decimalInteger})((${frac2})|\\.)?|(${frac2}))[eE][+-]?(${decimalDigits2})\\b` },
1749
+ { begin: `\\b(${decimalInteger})\\b((${frac2})\\b|\\.)?|(${frac2})\\b` },
1750
+ // DecimalBigIntegerLiteral
1751
+ { begin: `\\b(0|[1-9](_?[0-9])*)n\\b` },
1752
+ // NonDecimalIntegerLiteral
1753
+ { begin: "\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b" },
1754
+ { begin: "\\b0[bB][0-1](_?[0-1])*n?\\b" },
1755
+ { begin: "\\b0[oO][0-7](_?[0-7])*n?\\b" },
1756
+ // LegacyOctalIntegerLiteral (does not include underscore separators)
1757
+ // https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals
1758
+ { begin: "\\b0[0-7]+n?\\b" }
1759
+ ],
1760
+ relevance: 0
1761
+ };
1762
+ const SUBST = {
1763
+ className: "subst",
1764
+ begin: "\\$\\{",
1765
+ end: "\\}",
1766
+ keywords: KEYWORDS$1,
1767
+ contains: []
1768
+ // defined later
1769
+ };
1770
+ const HTML_TEMPLATE = {
1771
+ begin: ".?html`",
1772
+ end: "",
1773
+ starts: {
1774
+ end: "`",
1775
+ returnEnd: false,
1776
+ contains: [
1777
+ hljs.BACKSLASH_ESCAPE,
1778
+ SUBST
1779
+ ],
1780
+ subLanguage: "xml"
1781
+ }
1782
+ };
1783
+ const CSS_TEMPLATE = {
1784
+ begin: ".?css`",
1785
+ end: "",
1786
+ starts: {
1787
+ end: "`",
1788
+ returnEnd: false,
1789
+ contains: [
1790
+ hljs.BACKSLASH_ESCAPE,
1791
+ SUBST
1792
+ ],
1793
+ subLanguage: "css"
1794
+ }
1795
+ };
1796
+ const GRAPHQL_TEMPLATE = {
1797
+ begin: ".?gql`",
1798
+ end: "",
1799
+ starts: {
1800
+ end: "`",
1801
+ returnEnd: false,
1802
+ contains: [
1803
+ hljs.BACKSLASH_ESCAPE,
1804
+ SUBST
1805
+ ],
1806
+ subLanguage: "graphql"
1807
+ }
1808
+ };
1809
+ const TEMPLATE_STRING = {
1810
+ className: "string",
1811
+ begin: "`",
1812
+ end: "`",
1813
+ contains: [
1814
+ hljs.BACKSLASH_ESCAPE,
1815
+ SUBST
1816
+ ]
1817
+ };
1818
+ const JSDOC_COMMENT = hljs.COMMENT(
1819
+ /\/\*\*(?!\/)/,
1820
+ "\\*/",
1821
+ {
1822
+ relevance: 0,
1823
+ contains: [
1824
+ {
1825
+ begin: "(?=@[A-Za-z]+)",
1826
+ relevance: 0,
1827
+ contains: [
1828
+ {
1829
+ className: "doctag",
1830
+ begin: "@[A-Za-z]+"
1831
+ },
1832
+ {
1833
+ className: "type",
1834
+ begin: "\\{",
1835
+ end: "\\}",
1836
+ excludeEnd: true,
1837
+ excludeBegin: true,
1838
+ relevance: 0
1839
+ },
1840
+ {
1841
+ className: "variable",
1842
+ begin: IDENT_RE$1 + "(?=\\s*(-)|$)",
1843
+ endsParent: true,
1844
+ relevance: 0
1845
+ },
1846
+ // eat spaces (not newlines) so we can find
1847
+ // types or variables
1848
+ {
1849
+ begin: /(?=[^\n])\s/,
1850
+ relevance: 0
1851
+ }
1852
+ ]
1853
+ }
1854
+ ]
1855
+ }
1856
+ );
1857
+ const COMMENT = {
1858
+ className: "comment",
1859
+ variants: [
1860
+ JSDOC_COMMENT,
1861
+ hljs.C_BLOCK_COMMENT_MODE,
1862
+ hljs.C_LINE_COMMENT_MODE
1863
+ ]
1864
+ };
1865
+ const SUBST_INTERNALS = [
1866
+ hljs.APOS_STRING_MODE,
1867
+ hljs.QUOTE_STRING_MODE,
1868
+ HTML_TEMPLATE,
1869
+ CSS_TEMPLATE,
1870
+ GRAPHQL_TEMPLATE,
1871
+ TEMPLATE_STRING,
1872
+ // Skip numbers when they are part of a variable name
1873
+ { match: /\$\d+/ },
1874
+ NUMBER
1875
+ // This is intentional:
1876
+ // See https://github.com/highlightjs/highlight.js/issues/3288
1877
+ // hljs.REGEXP_MODE
1878
+ ];
1879
+ SUBST.contains = SUBST_INTERNALS.concat({
1880
+ // we need to pair up {} inside our subst to prevent
1881
+ // it from ending too early by matching another }
1882
+ begin: /\{/,
1883
+ end: /\}/,
1884
+ keywords: KEYWORDS$1,
1885
+ contains: [
1886
+ "self"
1887
+ ].concat(SUBST_INTERNALS)
1888
+ });
1889
+ const SUBST_AND_COMMENTS = [].concat(COMMENT, SUBST.contains);
1890
+ const PARAMS_CONTAINS = SUBST_AND_COMMENTS.concat([
1891
+ // eat recursive parens in sub expressions
1892
+ {
1893
+ begin: /(\s*)\(/,
1894
+ end: /\)/,
1895
+ keywords: KEYWORDS$1,
1896
+ contains: ["self"].concat(SUBST_AND_COMMENTS)
1897
+ }
1898
+ ]);
1899
+ const PARAMS = {
1900
+ className: "params",
1901
+ // convert this to negative lookbehind in v12
1902
+ begin: /(\s*)\(/,
1903
+ // to match the parms with
1904
+ end: /\)/,
1905
+ excludeBegin: true,
1906
+ excludeEnd: true,
1907
+ keywords: KEYWORDS$1,
1908
+ contains: PARAMS_CONTAINS
1909
+ };
1910
+ const CLASS_OR_EXTENDS = {
1911
+ variants: [
1912
+ // class Car extends vehicle
1913
+ {
1914
+ match: [
1915
+ /class/,
1916
+ /\s+/,
1917
+ IDENT_RE$1,
1918
+ /\s+/,
1919
+ /extends/,
1920
+ /\s+/,
1921
+ regex.concat(IDENT_RE$1, "(", regex.concat(/\./, IDENT_RE$1), ")*")
1922
+ ],
1923
+ scope: {
1924
+ 1: "keyword",
1925
+ 3: "title.class",
1926
+ 5: "keyword",
1927
+ 7: "title.class.inherited"
1928
+ }
1929
+ },
1930
+ // class Car
1931
+ {
1932
+ match: [
1933
+ /class/,
1934
+ /\s+/,
1935
+ IDENT_RE$1
1936
+ ],
1937
+ scope: {
1938
+ 1: "keyword",
1939
+ 3: "title.class"
1940
+ }
1941
+ }
1942
+ ]
1943
+ };
1944
+ const CLASS_REFERENCE = {
1945
+ relevance: 0,
1946
+ match: regex.either(
1947
+ // Hard coded exceptions
1948
+ /\bJSON/,
1949
+ // Float32Array, OutT
1950
+ /\b[A-Z][a-z]+([A-Z][a-z]*|\d)*/,
1951
+ // CSSFactory, CSSFactoryT
1952
+ /\b[A-Z]{2,}([A-Z][a-z]+|\d)+([A-Z][a-z]*)*/,
1953
+ // FPs, FPsT
1954
+ /\b[A-Z]{2,}[a-z]+([A-Z][a-z]+|\d)*([A-Z][a-z]*)*/
1955
+ // P
1956
+ // single letters are not highlighted
1957
+ // BLAH
1958
+ // this will be flagged as a UPPER_CASE_CONSTANT instead
1959
+ ),
1960
+ className: "title.class",
1961
+ keywords: {
1962
+ _: [
1963
+ // se we still get relevance credit for JS library classes
1964
+ ...TYPES2,
1965
+ ...ERROR_TYPES2
1966
+ ]
1967
+ }
1968
+ };
1969
+ const USE_STRICT = {
1970
+ label: "use_strict",
1971
+ className: "meta",
1972
+ relevance: 10,
1973
+ begin: /^\s*['"]use (strict|asm)['"]/
1974
+ };
1975
+ const FUNCTION_DEFINITION = {
1976
+ variants: [
1977
+ {
1978
+ match: [
1979
+ /function/,
1980
+ /\s+/,
1981
+ IDENT_RE$1,
1982
+ /(?=\s*\()/
1983
+ ]
1984
+ },
1985
+ // anonymous function
1986
+ {
1987
+ match: [
1988
+ /function/,
1989
+ /\s*(?=\()/
1990
+ ]
1991
+ }
1992
+ ],
1993
+ className: {
1994
+ 1: "keyword",
1995
+ 3: "title.function"
1996
+ },
1997
+ label: "func.def",
1998
+ contains: [PARAMS],
1999
+ illegal: /%/
2000
+ };
2001
+ const UPPER_CASE_CONSTANT = {
2002
+ relevance: 0,
2003
+ match: /\b[A-Z][A-Z_0-9]+\b/,
2004
+ className: "variable.constant"
2005
+ };
2006
+ function noneOf(list) {
2007
+ return regex.concat("(?!", list.join("|"), ")");
2008
+ }
2009
+ const FUNCTION_CALL = {
2010
+ match: regex.concat(
2011
+ /\b/,
2012
+ noneOf([
2013
+ ...BUILT_IN_GLOBALS2,
2014
+ "super",
2015
+ "import",
2016
+ "await"
2017
+ ].map((x) => `${x}\\s*\\(`)),
2018
+ IDENT_RE$1,
2019
+ regex.lookahead(/\s*\(/)
2020
+ ),
2021
+ className: "title.function",
2022
+ relevance: 0
2023
+ };
2024
+ const PROPERTY_ACCESS = {
2025
+ begin: regex.concat(/\./, regex.lookahead(
2026
+ regex.concat(IDENT_RE$1, /(?![0-9A-Za-z$_(])/)
2027
+ )),
2028
+ end: IDENT_RE$1,
2029
+ excludeBegin: true,
2030
+ keywords: "prototype",
2031
+ className: "property",
2032
+ relevance: 0
2033
+ };
2034
+ const GETTER_OR_SETTER = {
2035
+ match: [
2036
+ /get|set/,
2037
+ /\s+/,
2038
+ IDENT_RE$1,
2039
+ /(?=\()/
2040
+ ],
2041
+ className: {
2042
+ 1: "keyword",
2043
+ 3: "title.function"
2044
+ },
2045
+ contains: [
2046
+ {
2047
+ // eat to avoid empty params
2048
+ begin: /\(\)/
2049
+ },
2050
+ PARAMS
2051
+ ]
2052
+ };
2053
+ const FUNC_LEAD_IN_RE = "(\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)|" + hljs.UNDERSCORE_IDENT_RE + ")\\s*=>";
2054
+ const FUNCTION_VARIABLE = {
2055
+ match: [
2056
+ /const|var|let/,
2057
+ /\s+/,
2058
+ IDENT_RE$1,
2059
+ /\s*/,
2060
+ /=\s*/,
2061
+ /(async\s*)?/,
2062
+ // async is optional
2063
+ regex.lookahead(FUNC_LEAD_IN_RE)
2064
+ ],
2065
+ keywords: "async",
2066
+ className: {
2067
+ 1: "keyword",
2068
+ 3: "title.function"
2069
+ },
2070
+ contains: [
2071
+ PARAMS
2072
+ ]
2073
+ };
2074
+ return {
2075
+ name: "JavaScript",
2076
+ aliases: ["js", "jsx", "mjs", "cjs"],
2077
+ keywords: KEYWORDS$1,
2078
+ // this will be extended by TypeScript
2079
+ exports: { PARAMS_CONTAINS, CLASS_REFERENCE },
2080
+ illegal: /#(?![$_A-Za-z])/,
2081
+ contains: [
2082
+ hljs.SHEBANG({
2083
+ label: "shebang",
2084
+ binary: "node",
2085
+ relevance: 5
2086
+ }),
2087
+ USE_STRICT,
2088
+ hljs.APOS_STRING_MODE,
2089
+ hljs.QUOTE_STRING_MODE,
2090
+ HTML_TEMPLATE,
2091
+ CSS_TEMPLATE,
2092
+ GRAPHQL_TEMPLATE,
2093
+ TEMPLATE_STRING,
2094
+ COMMENT,
2095
+ // Skip numbers when they are part of a variable name
2096
+ { match: /\$\d+/ },
2097
+ NUMBER,
2098
+ CLASS_REFERENCE,
2099
+ {
2100
+ scope: "attr",
2101
+ match: IDENT_RE$1 + regex.lookahead(":"),
2102
+ relevance: 0
2103
+ },
2104
+ FUNCTION_VARIABLE,
2105
+ {
2106
+ // "value" container
2107
+ begin: "(" + hljs.RE_STARTERS_RE + "|\\b(case|return|throw)\\b)\\s*",
2108
+ keywords: "return throw case",
2109
+ relevance: 0,
2110
+ contains: [
2111
+ COMMENT,
2112
+ hljs.REGEXP_MODE,
2113
+ {
2114
+ className: "function",
2115
+ // we have to count the parens to make sure we actually have the
2116
+ // correct bounding ( ) before the =>. There could be any number of
2117
+ // sub-expressions inside also surrounded by parens.
2118
+ begin: FUNC_LEAD_IN_RE,
2119
+ returnBegin: true,
2120
+ end: "\\s*=>",
2121
+ contains: [
2122
+ {
2123
+ className: "params",
2124
+ variants: [
2125
+ {
2126
+ begin: hljs.UNDERSCORE_IDENT_RE,
2127
+ relevance: 0
2128
+ },
2129
+ {
2130
+ className: null,
2131
+ begin: /\(\s*\)/,
2132
+ skip: true
2133
+ },
2134
+ {
2135
+ begin: /(\s*)\(/,
2136
+ end: /\)/,
2137
+ excludeBegin: true,
2138
+ excludeEnd: true,
2139
+ keywords: KEYWORDS$1,
2140
+ contains: PARAMS_CONTAINS
2141
+ }
2142
+ ]
2143
+ }
2144
+ ]
2145
+ },
2146
+ {
2147
+ // could be a comma delimited list of params to a function call
2148
+ begin: /,/,
2149
+ relevance: 0
2150
+ },
2151
+ {
2152
+ match: /\s+/,
2153
+ relevance: 0
2154
+ },
2155
+ {
2156
+ // JSX
2157
+ variants: [
2158
+ { begin: FRAGMENT.begin, end: FRAGMENT.end },
2159
+ { match: XML_SELF_CLOSING },
2160
+ {
2161
+ begin: XML_TAG.begin,
2162
+ // we carefully check the opening tag to see if it truly
2163
+ // is a tag and not a false positive
2164
+ "on:begin": XML_TAG.isTrulyOpeningTag,
2165
+ end: XML_TAG.end
2166
+ }
2167
+ ],
2168
+ subLanguage: "xml",
2169
+ contains: [
2170
+ {
2171
+ begin: XML_TAG.begin,
2172
+ end: XML_TAG.end,
2173
+ skip: true,
2174
+ contains: ["self"]
2175
+ }
2176
+ ]
2177
+ }
2178
+ ]
2179
+ },
2180
+ FUNCTION_DEFINITION,
2181
+ {
2182
+ // prevent this from getting swallowed up by function
2183
+ // since they appear "function like"
2184
+ beginKeywords: "while if switch catch for"
2185
+ },
2186
+ {
2187
+ // we have to count the parens to make sure we actually have the correct
2188
+ // bounding ( ). There could be any number of sub-expressions inside
2189
+ // also surrounded by parens.
2190
+ begin: "\\b(?!function)" + hljs.UNDERSCORE_IDENT_RE + "\\([^()]*(\\([^()]*(\\([^()]*\\)[^()]*)*\\)[^()]*)*\\)\\s*\\{",
2191
+ // end parens
2192
+ returnBegin: true,
2193
+ label: "func.def",
2194
+ contains: [
2195
+ PARAMS,
2196
+ hljs.inherit(hljs.TITLE_MODE, { begin: IDENT_RE$1, className: "title.function" })
2197
+ ]
2198
+ },
2199
+ // catch ... so it won't trigger the property rule below
2200
+ {
2201
+ match: /\.\.\./,
2202
+ relevance: 0
2203
+ },
2204
+ PROPERTY_ACCESS,
2205
+ // hack: prevents detection of keywords in some circumstances
2206
+ // .keyword()
2207
+ // $keyword = x
2208
+ {
2209
+ match: "\\$" + IDENT_RE$1,
2210
+ relevance: 0
2211
+ },
2212
+ {
2213
+ match: [/\bconstructor(?=\s*\()/],
2214
+ className: { 1: "title.function" },
2215
+ contains: [PARAMS]
2216
+ },
2217
+ FUNCTION_CALL,
2218
+ UPPER_CASE_CONSTANT,
2219
+ CLASS_OR_EXTENDS,
2220
+ GETTER_OR_SETTER,
2221
+ {
2222
+ match: /\$[(.]/
2223
+ // relevance booster for a pattern common to JS libs: `$(something)` and `$.something`
2224
+ }
2225
+ ]
2226
+ };
2227
+ }
2228
+
2229
+ // node_modules/highlight.js/es/languages/java.js
2230
+ var decimalDigits = "[0-9](_*[0-9])*";
2231
+ var frac = `\\.(${decimalDigits})`;
2232
+ var hexDigits = "[0-9a-fA-F](_*[0-9a-fA-F])*";
2233
+ var NUMERIC = {
2234
+ className: "number",
2235
+ variants: [
2236
+ // DecimalFloatingPointLiteral
2237
+ // including ExponentPart
2238
+ { begin: `(\\b(${decimalDigits})((${frac})|\\.)?|(${frac}))[eE][+-]?(${decimalDigits})[fFdD]?\\b` },
2239
+ // excluding ExponentPart
2240
+ { begin: `\\b(${decimalDigits})((${frac})[fFdD]?\\b|\\.([fFdD]\\b)?)` },
2241
+ { begin: `(${frac})[fFdD]?\\b` },
2242
+ { begin: `\\b(${decimalDigits})[fFdD]\\b` },
2243
+ // HexadecimalFloatingPointLiteral
2244
+ { begin: `\\b0[xX]((${hexDigits})\\.?|(${hexDigits})?\\.(${hexDigits}))[pP][+-]?(${decimalDigits})[fFdD]?\\b` },
2245
+ // DecimalIntegerLiteral
2246
+ { begin: "\\b(0|[1-9](_*[0-9])*)[lL]?\\b" },
2247
+ // HexIntegerLiteral
2248
+ { begin: `\\b0[xX](${hexDigits})[lL]?\\b` },
2249
+ // OctalIntegerLiteral
2250
+ { begin: "\\b0(_*[0-7])*[lL]?\\b" },
2251
+ // BinaryIntegerLiteral
2252
+ { begin: "\\b0[bB][01](_*[01])*[lL]?\\b" }
2253
+ ],
2254
+ relevance: 0
2255
+ };
2256
+ function recurRegex(re, substitution, depth) {
2257
+ if (depth === -1) return "";
2258
+ return re.replace(substitution, (_) => {
2259
+ return recurRegex(re, substitution, depth - 1);
2260
+ });
2261
+ }
2262
+ function java(hljs) {
2263
+ const regex = hljs.regex;
2264
+ const JAVA_IDENT_RE = "[\xC0-\u02B8a-zA-Z_$][\xC0-\u02B8a-zA-Z_$0-9]*";
2265
+ const ARRAY_BRACKETS_OPTIONAL_RE = "(?:(?:\\s*\\[\\s*])+)?";
2266
+ const SIMPLE_TYPE_RE = JAVA_IDENT_RE + "<@@@>" + ARRAY_BRACKETS_OPTIONAL_RE;
2267
+ const WILDCARD_TYPE_RE = "\\?(?:\\s+(?:extends|super)\\s+" + SIMPLE_TYPE_RE + ")?";
2268
+ const TYPE_ARG_RE = "(?:" + WILDCARD_TYPE_RE + "|" + SIMPLE_TYPE_RE + ")";
2269
+ const TYPE_ARGS_OPTIONAL_RE = recurRegex(
2270
+ "(?:\\s*<\\s*" + TYPE_ARG_RE + "(?:\\s*,\\s*" + TYPE_ARG_RE + ")*\\s*>)?",
2271
+ /<@@@>/g,
2272
+ 2
2273
+ );
2274
+ const MAIN_KEYWORDS = [
2275
+ "synchronized",
2276
+ "abstract",
2277
+ "private",
2278
+ "var",
2279
+ "static",
2280
+ "if",
2281
+ "const ",
2282
+ "for",
2283
+ "while",
2284
+ "strictfp",
2285
+ "finally",
2286
+ "protected",
2287
+ "import",
2288
+ "native",
2289
+ "final",
2290
+ "void",
2291
+ "enum",
2292
+ "else",
2293
+ "break",
2294
+ "transient",
2295
+ "catch",
2296
+ "instanceof",
2297
+ "volatile",
2298
+ "case",
2299
+ "assert",
2300
+ "package",
2301
+ "default",
2302
+ "public",
2303
+ "try",
2304
+ "switch",
2305
+ "continue",
2306
+ "throws",
2307
+ "protected",
2308
+ "public",
2309
+ "private",
2310
+ "module",
2311
+ "requires",
2312
+ "exports",
2313
+ "do",
2314
+ "sealed",
2315
+ "yield",
2316
+ "permits",
2317
+ "goto",
2318
+ "when"
2319
+ ];
2320
+ const BUILT_INS3 = [
2321
+ "super",
2322
+ "this"
2323
+ ];
2324
+ const LITERALS3 = [
2325
+ "false",
2326
+ "true",
2327
+ "null"
2328
+ ];
2329
+ const TYPES3 = [
2330
+ "char",
2331
+ "boolean",
2332
+ "long",
2333
+ "float",
2334
+ "int",
2335
+ "byte",
2336
+ "short",
2337
+ "double"
2338
+ ];
2339
+ const KEYWORDS3 = {
2340
+ keyword: MAIN_KEYWORDS,
2341
+ literal: LITERALS3,
2342
+ type: TYPES3,
2343
+ built_in: BUILT_INS3
2344
+ };
2345
+ const ANNOTATION = {
2346
+ className: "meta",
2347
+ begin: "@" + JAVA_IDENT_RE,
2348
+ contains: [
2349
+ {
2350
+ begin: /\(/,
2351
+ end: /\)/,
2352
+ contains: ["self"]
2353
+ // allow nested () inside our annotation
2354
+ }
2355
+ ]
2356
+ };
2357
+ const PARAMS = {
2358
+ className: "params",
2359
+ begin: /\(/,
2360
+ end: /\)/,
2361
+ keywords: KEYWORDS3,
2362
+ relevance: 0,
2363
+ contains: [hljs.C_BLOCK_COMMENT_MODE],
2364
+ endsParent: true
2365
+ };
2366
+ return {
2367
+ name: "Java",
2368
+ aliases: ["jsp"],
2369
+ keywords: KEYWORDS3,
2370
+ illegal: /<\/|#/,
2371
+ contains: [
2372
+ hljs.COMMENT(
2373
+ "/\\*\\*",
2374
+ "\\*/",
2375
+ {
2376
+ relevance: 0,
2377
+ contains: [
2378
+ {
2379
+ // eat up @'s in emails to prevent them to be recognized as doctags
2380
+ begin: /\w+@/,
2381
+ relevance: 0
2382
+ },
2383
+ {
2384
+ className: "doctag",
2385
+ begin: "@[A-Za-z]+"
2386
+ }
2387
+ ]
2388
+ }
2389
+ ),
2390
+ // relevance boost
2391
+ {
2392
+ begin: /import java\.[a-z]+\./,
2393
+ keywords: "import",
2394
+ relevance: 2
2395
+ },
2396
+ hljs.C_LINE_COMMENT_MODE,
2397
+ hljs.C_BLOCK_COMMENT_MODE,
2398
+ {
2399
+ begin: /"""/,
2400
+ end: /"""/,
2401
+ className: "string",
2402
+ contains: [hljs.BACKSLASH_ESCAPE]
2403
+ },
2404
+ hljs.APOS_STRING_MODE,
2405
+ hljs.QUOTE_STRING_MODE,
2406
+ {
2407
+ match: [
2408
+ /\b(?:class|interface|enum|extends|implements|new)/,
2409
+ /\s+/,
2410
+ JAVA_IDENT_RE
2411
+ ],
2412
+ className: {
2413
+ 1: "keyword",
2414
+ 3: "title.class"
2415
+ }
2416
+ },
2417
+ {
2418
+ // Exceptions for hyphenated keywords
2419
+ match: /non-sealed/,
2420
+ scope: "keyword"
2421
+ },
2422
+ {
2423
+ // Expression keywords prevent keyword-led expressions from being
2424
+ // recognized as variable or method declarations.
2425
+ beginKeywords: "new throw return else yield assert",
2426
+ relevance: 0
2427
+ },
2428
+ {
2429
+ begin: [
2430
+ JAVA_IDENT_RE,
2431
+ regex.concat(TYPE_ARGS_OPTIONAL_RE, ARRAY_BRACKETS_OPTIONAL_RE, /\s+/),
2432
+ JAVA_IDENT_RE,
2433
+ ARRAY_BRACKETS_OPTIONAL_RE,
2434
+ /\s*/,
2435
+ /=(?!=)/
2436
+ ],
2437
+ className: {
2438
+ 1: "type",
2439
+ 3: "variable",
2440
+ 6: "operator"
2441
+ }
2442
+ },
2443
+ {
2444
+ begin: [
2445
+ /record/,
2446
+ /\s+/,
2447
+ JAVA_IDENT_RE
2448
+ ],
2449
+ className: {
2450
+ 1: "keyword",
2451
+ 3: "title.class"
2452
+ },
2453
+ contains: [
2454
+ PARAMS,
2455
+ hljs.C_LINE_COMMENT_MODE,
2456
+ hljs.C_BLOCK_COMMENT_MODE
2457
+ ]
2458
+ },
2459
+ {
2460
+ begin: [
2461
+ JAVA_IDENT_RE,
2462
+ regex.concat(TYPE_ARGS_OPTIONAL_RE, ARRAY_BRACKETS_OPTIONAL_RE, /\s+/),
2463
+ JAVA_IDENT_RE,
2464
+ /\s*(?=\()/
2465
+ ],
2466
+ className: {
2467
+ 1: "type",
2468
+ 3: "title.function"
2469
+ },
2470
+ keywords: KEYWORDS3,
2471
+ contains: [
2472
+ {
2473
+ className: "params",
2474
+ begin: /\(/,
2475
+ end: /\)/,
2476
+ keywords: KEYWORDS3,
2477
+ relevance: 0,
2478
+ contains: [
2479
+ ANNOTATION,
2480
+ hljs.APOS_STRING_MODE,
2481
+ hljs.QUOTE_STRING_MODE,
2482
+ NUMERIC,
2483
+ hljs.C_BLOCK_COMMENT_MODE
2484
+ ]
2485
+ },
2486
+ hljs.C_LINE_COMMENT_MODE,
2487
+ hljs.C_BLOCK_COMMENT_MODE
2488
+ ]
2489
+ },
2490
+ NUMERIC,
2491
+ ANNOTATION
2492
+ ]
2493
+ };
2494
+ }
2495
+
2496
+ // src/components/MarkdownEditor/markdown/pipeline.ts
2497
+ import { unified } from "unified";
2498
+ import remarkParse from "remark-parse";
2499
+ import remarkGfm from "remark-gfm";
2500
+ import remarkRehype from "remark-rehype";
2501
+ import remarkStringify from "remark-stringify";
2502
+ import rehypeStringify from "rehype-stringify";
2503
+ import rehypeParse from "rehype-parse";
2504
+ import rehypeRaw from "rehype-raw";
2505
+ import rehypeRemark from "rehype-remark";
2506
+ import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
2507
+ import rehypeHighlight from "rehype-highlight";
2508
+ import { visit } from "unist-util-visit";
2509
+ var HIGHLIGHT_LANGUAGES = { json, sql, typescript, javascript: javascript2, java };
2510
+ var sanitizeSchemaWithHighlight = {
2511
+ ...defaultSchema,
2512
+ attributes: {
2513
+ ...defaultSchema.attributes,
2514
+ code: [...defaultSchema.attributes?.code ?? [], "className"],
2515
+ span: [...defaultSchema.attributes?.span ?? [], "className"]
2516
+ }
2517
+ };
2518
+ var STRINGIFY_OPTIONS = {
2519
+ bullet: "-",
2520
+ listItemIndent: "one",
2521
+ fences: true,
2522
+ rule: "-"
2523
+ };
2524
+ function isElement(node) {
2525
+ return node.type === "element";
2526
+ }
2527
+ function embedRawHtml() {
2528
+ return (tree) => {
2529
+ visit(tree, "html", (node, index, parent) => {
2530
+ if (parent === void 0 || index === void 0) return;
2531
+ if (parent.type === "paragraph") {
2532
+ parent.children[index] = { type: "text", value: node.value };
2533
+ } else {
2534
+ const placeholder = {
2535
+ type: "htmlEmbed",
2536
+ data: {
2537
+ hName: "div",
2538
+ hProperties: { dataRawHtml: encodeURIComponent(node.value) }
2539
+ }
2540
+ };
2541
+ parent.children[index] = placeholder;
2542
+ }
2543
+ });
2544
+ };
2545
+ }
2546
+ function taskListsToTiptap() {
2547
+ return (tree) => {
2548
+ visit(tree, "element", (node) => {
2549
+ if (node.tagName !== "li") return;
2550
+ const classes = Array.isArray(node.properties.className) ? node.properties.className : [];
2551
+ if (!classes.includes("task-list-item")) return;
2552
+ let checked = false;
2553
+ node.children = node.children.filter((child) => {
2554
+ if (isElement(child) && child.tagName === "input") {
2555
+ checked = child.properties.checked === true;
2556
+ return false;
2557
+ }
2558
+ return true;
2559
+ });
2560
+ node.properties.dataType = "taskItem";
2561
+ node.properties.dataChecked = String(checked);
2562
+ node.properties.className = void 0;
2563
+ });
2564
+ visit(tree, "element", (node) => {
2565
+ if (node.tagName !== "ul") return;
2566
+ const hasTaskItem = node.children.some(
2567
+ (child) => isElement(child) && child.properties.dataType === "taskItem"
2568
+ );
2569
+ if (hasTaskItem) {
2570
+ node.properties.dataType = "taskList";
2571
+ node.properties.className = void 0;
2572
+ }
2573
+ });
2574
+ };
2575
+ }
2576
+ function tiptapTaskListsToGfm() {
2577
+ return (tree) => {
2578
+ visit(tree, "element", (node) => {
2579
+ if (node.tagName !== "li" || node.properties.dataType !== "taskItem") {
2580
+ return;
2581
+ }
2582
+ const checked = node.properties.dataChecked === "true";
2583
+ const content = [];
2584
+ for (const child of node.children) {
2585
+ if (isElement(child) && child.tagName === "label") continue;
2586
+ if (isElement(child) && child.tagName === "div") {
2587
+ content.push(...child.children);
2588
+ } else {
2589
+ content.push(child);
2590
+ }
2591
+ }
2592
+ const checkbox = {
2593
+ type: "element",
2594
+ tagName: "input",
2595
+ properties: { type: "checkbox", checked, disabled: true },
2596
+ children: []
2597
+ };
2598
+ node.children = [checkbox, ...content];
2599
+ });
2600
+ };
2601
+ }
2602
+ function tightenListItems() {
2603
+ return (tree) => {
2604
+ visit(tree, "element", (node) => {
2605
+ if (node.tagName !== "li") return;
2606
+ const paragraphs = node.children.filter(
2607
+ (child) => isElement(child) && child.tagName === "p"
2608
+ );
2609
+ if (paragraphs.length !== 1) return;
2610
+ node.children = node.children.flatMap(
2611
+ (child) => isElement(child) && child.tagName === "p" ? child.children : [child]
2612
+ );
2613
+ });
2614
+ };
2615
+ }
2616
+ function markdownToEditorHtml(markdown) {
2617
+ const file = unified().use(remarkParse).use(remarkGfm).use(embedRawHtml).use(remarkRehype).use(taskListsToTiptap).use(rehypeStringify).processSync(markdown);
2618
+ return String(file);
2619
+ }
2620
+ function editorHtmlToMarkdown(html) {
2621
+ const file = unified().use(rehypeParse, { fragment: true }).use(tiptapTaskListsToGfm).use(tightenListItems).use(rehypeRemark, {
2622
+ handlers: {
2623
+ div(state, node) {
2624
+ const raw = node.properties.dataRawHtml;
2625
+ if (typeof raw === "string") {
2626
+ return { type: "html", value: decodeURIComponent(raw) };
2627
+ }
2628
+ return state.all(node);
2629
+ }
2630
+ }
2631
+ }).use(remarkGfm).use(remarkStringify, STRINGIFY_OPTIONS).processSync(html);
2632
+ return String(file);
2633
+ }
2634
+ function markdownToHtml(markdown, options) {
2635
+ const processor = unified().use(remarkParse).use(remarkGfm).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeRaw).use(rehypeHighlight, {
2636
+ languages: HIGHLIGHT_LANGUAGES,
2637
+ ignoreMissing: true
2638
+ });
2639
+ const withSanitize = options.sanitize ? processor.use(rehypeSanitize, sanitizeSchemaWithHighlight) : processor;
2640
+ const file = withSanitize.use(rehypeStringify).processSync(markdown);
2641
+ return String(file);
2642
+ }
2643
+ function sanitizeHtmlFragment(html) {
2644
+ const file = unified().use(rehypeParse, { fragment: true }).use(rehypeSanitize).use(rehypeStringify).processSync(html);
2645
+ return String(file);
2646
+ }
2647
+
2648
+ // src/components/MarkdownEditor/markdown/tiptapMarkdownBridge.ts
2649
+ var lowlight = createLowlight();
2650
+ lowlight.register({ json, sql, typescript, javascript: javascript2, java });
2651
+ var HtmlBlock = Node.create({
2652
+ name: "htmlBlock",
2653
+ group: "block",
2654
+ atom: true,
2655
+ addOptions() {
2656
+ return { sanitize: true };
2657
+ },
2658
+ addAttributes() {
2659
+ return { content: { default: "" } };
2660
+ },
2661
+ parseHTML() {
2662
+ return [
2663
+ {
2664
+ tag: "div[data-raw-html]",
2665
+ getAttrs: (element) => {
2666
+ const raw = element.getAttribute("data-raw-html");
2667
+ return raw === null ? false : { content: decodeURIComponent(raw) };
2668
+ }
2669
+ }
2670
+ ];
2671
+ },
2672
+ renderHTML({ node }) {
2673
+ const content = node.attrs["content"];
2674
+ return ["div", { "data-raw-html": encodeURIComponent(content) }];
2675
+ },
2676
+ addNodeView() {
2677
+ return ({ node }) => {
2678
+ const dom = document.createElement("div");
2679
+ dom.setAttribute("data-html-block", "");
2680
+ const raw = node.attrs["content"];
2681
+ dom.innerHTML = this.options.sanitize ? sanitizeHtmlFragment(raw) : raw;
2682
+ return { dom };
2683
+ };
2684
+ }
2685
+ });
2686
+ function createEditorExtensions(options) {
2687
+ return [
2688
+ StarterKit.configure({ codeBlock: false }),
2689
+ CodeBlockLowlight.configure({ lowlight }),
2690
+ Table.configure({ resizable: false }),
2691
+ TableRow,
2692
+ TableHeader,
2693
+ TableCell,
2694
+ TaskList,
2695
+ TaskItem.configure({ nested: true }),
2696
+ Link.configure({ openOnClick: false }),
2697
+ Image,
2698
+ HtmlBlock.configure({ sanitize: options.sanitizeEmbeddedHtml })
2699
+ ];
2700
+ }
2701
+ function markdownToEditorContent(markdown) {
2702
+ return markdownToEditorHtml(markdown);
2703
+ }
2704
+ function editorToMarkdown(editor) {
2705
+ return editorHtmlToMarkdown(editor.getHTML());
2706
+ }
2707
+
2708
+ // src/components/MarkdownEditor/views/RenderedView.tsx
2709
+ import { EditorContent } from "@tiptap/react";
2710
+ import { jsx } from "react/jsx-runtime";
2711
+ function RenderedView({ editor }) {
2712
+ return /* @__PURE__ */ jsx(EditorContent, { editor });
2713
+ }
2714
+
2715
+ // src/components/MarkdownEditor/MarkdownEditor.module.css
2716
+ var MarkdownEditor_default = {};
2717
+
2718
+ // src/components/MarkdownEditor/views/MarkdownSourceView.tsx
2719
+ import { jsx as jsx2 } from "react/jsx-runtime";
2720
+ function MarkdownSourceView({
2721
+ value,
2722
+ onChange,
2723
+ readOnly = false
2724
+ }) {
2725
+ return /* @__PURE__ */ jsx2(
2726
+ "textarea",
2727
+ {
2728
+ className: MarkdownEditor_default["source"],
2729
+ "aria-label": "C\xF3digo fuente Markdown",
2730
+ spellCheck: false,
2731
+ value,
2732
+ readOnly,
2733
+ onChange: (event) => onChange(event.target.value)
2734
+ }
2735
+ );
2736
+ }
2737
+
2738
+ // src/components/MarkdownEditor/Toolbar/Toolbar.tsx
2739
+ import { useEffect as useEffect4, useReducer, useState as useState6 } from "react";
2740
+
2741
+ // src/components/MarkdownEditor/Toolbar/buttons/ToolbarButton.tsx
2742
+ import { jsx as jsx3 } from "react/jsx-runtime";
2743
+ function ToolbarButton({
2744
+ label,
2745
+ pressed,
2746
+ className,
2747
+ children,
2748
+ ...rest
2749
+ }) {
2750
+ const buttonClass = className === void 0 ? MarkdownEditor_default["button"] : `${MarkdownEditor_default["button"]} ${className}`;
2751
+ return /* @__PURE__ */ jsx3(
2752
+ "button",
2753
+ {
2754
+ type: "button",
2755
+ className: buttonClass,
2756
+ "aria-label": label,
2757
+ title: label,
2758
+ ...pressed !== void 0 ? { "aria-pressed": pressed } : {},
2759
+ ...rest,
2760
+ children
2761
+ }
2762
+ );
2763
+ }
2764
+
2765
+ // src/components/MarkdownEditor/Toolbar/buttons/InsertDialogs.tsx
2766
+ import {
2767
+ useEffect,
2768
+ useId,
2769
+ useRef,
2770
+ useState
2771
+ } from "react";
2772
+
2773
+ // src/components/MarkdownEditor/markdown/links.ts
2774
+ function ensureProtocol(url) {
2775
+ return url.includes("://") ? url : `http://${url}`;
2776
+ }
2777
+
2778
+ // src/components/MarkdownEditor/Toolbar/buttons/InsertDialogs.tsx
2779
+ import { jsx as jsx4, jsxs } from "react/jsx-runtime";
2780
+ function DialogShell({ title, onSubmit, onClose, children }) {
2781
+ const ref = useRef(null);
2782
+ useEffect(() => {
2783
+ const first = ref.current?.querySelector("input, textarea");
2784
+ first?.focus();
2785
+ }, []);
2786
+ const handleSubmit = (event) => {
2787
+ event.preventDefault();
2788
+ onSubmit();
2789
+ };
2790
+ return /* @__PURE__ */ jsxs(
2791
+ "form",
2792
+ {
2793
+ ref,
2794
+ className: MarkdownEditor_default["dialog"],
2795
+ role: "dialog",
2796
+ "aria-label": title,
2797
+ onSubmit: handleSubmit,
2798
+ onKeyDown: (event) => {
2799
+ if (event.key === "Escape") {
2800
+ event.stopPropagation();
2801
+ onClose();
2802
+ }
2803
+ },
2804
+ children: [
2805
+ children,
2806
+ /* @__PURE__ */ jsxs("div", { className: MarkdownEditor_default["dialogActions"], children: [
2807
+ /* @__PURE__ */ jsx4(
2808
+ "button",
2809
+ {
2810
+ type: "button",
2811
+ className: `${MarkdownEditor_default["button"]} ${MarkdownEditor_default["textButton"]}`,
2812
+ onClick: onClose,
2813
+ children: "Cancelar"
2814
+ }
2815
+ ),
2816
+ /* @__PURE__ */ jsx4(
2817
+ "button",
2818
+ {
2819
+ type: "submit",
2820
+ className: `${MarkdownEditor_default["button"]} ${MarkdownEditor_default["textButton"]}`,
2821
+ children: "Insertar"
2822
+ }
2823
+ )
2824
+ ] })
2825
+ ]
2826
+ }
2827
+ );
2828
+ }
2829
+ function Field({ label, children }) {
2830
+ const id = useId();
2831
+ return /* @__PURE__ */ jsxs("div", { className: MarkdownEditor_default["dialogField"], children: [
2832
+ /* @__PURE__ */ jsx4("label", { htmlFor: id, children: label }),
2833
+ children(id)
2834
+ ] });
2835
+ }
2836
+ function InsertDialog({ kind, editor, onClose }) {
2837
+ const [url, setUrl] = useState("");
2838
+ const [text, setText] = useState("");
2839
+ const [html, setHtml] = useState("");
2840
+ const [hasSelectionForLink] = useState(
2841
+ () => kind === "link" && !editor.state.selection.empty
2842
+ );
2843
+ const submit = () => {
2844
+ const chain = editor.chain().focus();
2845
+ if (kind === "image" && url) {
2846
+ chain.setImage({ src: url, alt: text }).run();
2847
+ } else if (kind === "link" && url) {
2848
+ const href = ensureProtocol(url);
2849
+ if (hasSelectionForLink) {
2850
+ chain.extendMarkRange("link").setLink({ href }).run();
2851
+ } else if (text) {
2852
+ chain.insertContent({
2853
+ type: "text",
2854
+ text,
2855
+ marks: [{ type: "link", attrs: { href } }]
2856
+ }).run();
2857
+ }
2858
+ } else if (kind === "html" && html) {
2859
+ chain.insertContent({ type: "htmlBlock", attrs: { content: html } }).run();
2860
+ }
2861
+ onClose();
2862
+ };
2863
+ if (kind === "html") {
2864
+ return /* @__PURE__ */ jsx4(
2865
+ DialogShell,
2866
+ {
2867
+ title: "Insertar HTML embebido",
2868
+ onSubmit: submit,
2869
+ onClose,
2870
+ children: /* @__PURE__ */ jsx4(Field, { label: "C\xF3digo HTML", children: (id) => /* @__PURE__ */ jsx4(
2871
+ "textarea",
2872
+ {
2873
+ id,
2874
+ rows: 4,
2875
+ value: html,
2876
+ onChange: (e) => setHtml(e.target.value)
2877
+ }
2878
+ ) })
2879
+ }
2880
+ );
2881
+ }
2882
+ const isImage = kind === "image";
2883
+ return /* @__PURE__ */ jsxs(
2884
+ DialogShell,
2885
+ {
2886
+ title: isImage ? "Insertar imagen" : "Insertar enlace",
2887
+ onSubmit: submit,
2888
+ onClose,
2889
+ children: [
2890
+ /* @__PURE__ */ jsx4(Field, { label: isImage ? "URL de la imagen" : "URL del enlace", children: (id) => /* @__PURE__ */ jsx4(
2891
+ "input",
2892
+ {
2893
+ id,
2894
+ type: isImage ? "url" : "text",
2895
+ required: true,
2896
+ value: url,
2897
+ onChange: (e) => setUrl(e.target.value)
2898
+ }
2899
+ ) }),
2900
+ !(kind === "link" && hasSelectionForLink) && /* @__PURE__ */ jsx4(Field, { label: isImage ? "Texto alternativo" : "Texto del enlace", children: (id) => /* @__PURE__ */ jsx4(
2901
+ "input",
2902
+ {
2903
+ id,
2904
+ type: "text",
2905
+ value: text,
2906
+ onChange: (e) => setText(e.target.value)
2907
+ }
2908
+ ) })
2909
+ ]
2910
+ }
2911
+ );
2912
+ }
2913
+
2914
+ // src/components/MarkdownEditor/Toolbar/buttons/TableSizePicker.tsx
2915
+ import { useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
2916
+ import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
2917
+ function TableSizePicker({
2918
+ maxCols = 10,
2919
+ maxRows = 10,
2920
+ onSelect,
2921
+ onClose
2922
+ }) {
2923
+ const [size, setSize] = useState2(null);
2924
+ const gridRef = useRef2(null);
2925
+ useEffect2(() => {
2926
+ gridRef.current?.focus();
2927
+ }, []);
2928
+ const clamp = (value, max) => Math.min(Math.max(value, 1), max);
2929
+ const handleKeyDown = (event) => {
2930
+ if (event.key === "Escape") {
2931
+ event.stopPropagation();
2932
+ onClose();
2933
+ return;
2934
+ }
2935
+ if (event.key === "Enter" || event.key === " ") {
2936
+ event.preventDefault();
2937
+ if (size !== null) onSelect(size);
2938
+ return;
2939
+ }
2940
+ const deltas = {
2941
+ ArrowRight: [1, 0],
2942
+ ArrowLeft: [-1, 0],
2943
+ ArrowDown: [0, 1],
2944
+ ArrowUp: [0, -1]
2945
+ };
2946
+ const delta = deltas[event.key];
2947
+ if (delta === void 0) return;
2948
+ event.preventDefault();
2949
+ const current = size ?? { cols: 0, rows: 0 };
2950
+ setSize({
2951
+ cols: clamp(current.cols + delta[0], maxCols),
2952
+ rows: clamp(current.rows + delta[1], maxRows)
2953
+ });
2954
+ };
2955
+ const label = size === null ? "Selecciona el tama\xF1o" : `${size.cols} \xD7 ${size.rows}`;
2956
+ return /* @__PURE__ */ jsxs2(
2957
+ "div",
2958
+ {
2959
+ className: `${MarkdownEditor_default["dialog"]} ${MarkdownEditor_default["tablePicker"]}`,
2960
+ role: "dialog",
2961
+ "aria-label": "Insertar tabla",
2962
+ children: [
2963
+ /* @__PURE__ */ jsx5("div", { className: MarkdownEditor_default["tablePickerLabel"], "aria-live": "polite", children: label }),
2964
+ /* @__PURE__ */ jsx5(
2965
+ "div",
2966
+ {
2967
+ ref: gridRef,
2968
+ className: MarkdownEditor_default["tablePickerGrid"],
2969
+ style: { gridTemplateColumns: `repeat(${maxCols}, 16px)` },
2970
+ tabIndex: 0,
2971
+ role: "group",
2972
+ "aria-label": "Tama\xF1o de la tabla (columnas \xD7 filas)",
2973
+ onKeyDown: handleKeyDown,
2974
+ children: Array.from(
2975
+ { length: maxRows },
2976
+ (_, rowIndex) => Array.from({ length: maxCols }, (_2, colIndex) => {
2977
+ const cell = {
2978
+ cols: colIndex + 1,
2979
+ rows: rowIndex + 1
2980
+ };
2981
+ const selected = size !== null && cell.cols <= size.cols && cell.rows <= size.rows;
2982
+ return /* @__PURE__ */ jsx5(
2983
+ "div",
2984
+ {
2985
+ className: MarkdownEditor_default["tablePickerCell"],
2986
+ "data-cell": `${cell.cols}x${cell.rows}`,
2987
+ "data-selected": selected ? "true" : "false",
2988
+ "aria-hidden": "true",
2989
+ onMouseEnter: () => setSize(cell),
2990
+ onClick: () => onSelect(cell)
2991
+ },
2992
+ `${cell.cols}x${cell.rows}`
2993
+ );
2994
+ })
2995
+ )
2996
+ }
2997
+ )
2998
+ ]
2999
+ }
3000
+ );
3001
+ }
3002
+
3003
+ // src/components/MarkdownEditor/Toolbar/buttons/CodeLanguagePicker.tsx
3004
+ import { useEffect as useEffect3, useId as useId2, useRef as useRef3, useState as useState3 } from "react";
3005
+ import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
3006
+ var CODE_LANGUAGES = [
3007
+ { value: "json", label: "JSON" },
3008
+ { value: "sql", label: "SQL" },
3009
+ { value: "typescript", label: "TypeScript" },
3010
+ { value: "javascript", label: "JavaScript" },
3011
+ { value: "java", label: "Java" }
3012
+ ];
3013
+ function CodeLanguagePicker({
3014
+ currentLanguage,
3015
+ onSelect,
3016
+ onClose
3017
+ }) {
3018
+ const isKnown = CODE_LANGUAGES.some(
3019
+ (lang) => lang.value === currentLanguage
3020
+ );
3021
+ const [choice, setChoice] = useState3(
3022
+ isKnown ? currentLanguage : "other"
3023
+ );
3024
+ const [otherValue, setOtherValue] = useState3(
3025
+ !isKnown && currentLanguage ? currentLanguage : ""
3026
+ );
3027
+ const formRef = useRef3(null);
3028
+ const otherFieldId = useId2();
3029
+ useEffect3(() => {
3030
+ formRef.current?.querySelector("select")?.focus();
3031
+ }, []);
3032
+ const submit = () => {
3033
+ const language = choice === "other" ? otherValue.trim() : choice;
3034
+ if (language) onSelect(language);
3035
+ };
3036
+ return /* @__PURE__ */ jsxs3(
3037
+ "form",
3038
+ {
3039
+ ref: formRef,
3040
+ className: MarkdownEditor_default["dialog"],
3041
+ role: "dialog",
3042
+ "aria-label": "Lenguaje del bloque de c\xF3digo",
3043
+ onSubmit: (event) => {
3044
+ event.preventDefault();
3045
+ submit();
3046
+ },
3047
+ onKeyDown: (event) => {
3048
+ if (event.key === "Escape") {
3049
+ event.stopPropagation();
3050
+ onClose();
3051
+ }
3052
+ },
3053
+ children: [
3054
+ /* @__PURE__ */ jsxs3("div", { className: MarkdownEditor_default["dialogField"], children: [
3055
+ /* @__PURE__ */ jsx6("label", { htmlFor: "mdw-code-language", children: "Lenguaje" }),
3056
+ /* @__PURE__ */ jsxs3(
3057
+ "select",
3058
+ {
3059
+ id: "mdw-code-language",
3060
+ value: choice,
3061
+ onChange: (event) => setChoice(event.target.value),
3062
+ children: [
3063
+ CODE_LANGUAGES.map((lang) => /* @__PURE__ */ jsx6("option", { value: lang.value, children: lang.label }, lang.value)),
3064
+ /* @__PURE__ */ jsx6("option", { value: "other", children: "Otro\u2026" })
3065
+ ]
3066
+ }
3067
+ )
3068
+ ] }),
3069
+ choice === "other" && /* @__PURE__ */ jsxs3("div", { className: MarkdownEditor_default["dialogField"], children: [
3070
+ /* @__PURE__ */ jsx6("label", { htmlFor: otherFieldId, children: "Especificar lenguaje" }),
3071
+ /* @__PURE__ */ jsx6(
3072
+ "input",
3073
+ {
3074
+ id: otherFieldId,
3075
+ type: "text",
3076
+ value: otherValue,
3077
+ onChange: (event) => setOtherValue(event.target.value)
3078
+ }
3079
+ )
3080
+ ] }),
3081
+ /* @__PURE__ */ jsxs3("div", { className: MarkdownEditor_default["dialogActions"], children: [
3082
+ /* @__PURE__ */ jsx6(
3083
+ "button",
3084
+ {
3085
+ type: "button",
3086
+ className: `${MarkdownEditor_default["button"]} ${MarkdownEditor_default["textButton"]}`,
3087
+ onClick: onClose,
3088
+ children: "Cancelar"
3089
+ }
3090
+ ),
3091
+ /* @__PURE__ */ jsx6(
3092
+ "button",
3093
+ {
3094
+ type: "submit",
3095
+ className: `${MarkdownEditor_default["button"]} ${MarkdownEditor_default["textButton"]}`,
3096
+ children: "Aplicar"
3097
+ }
3098
+ )
3099
+ ] })
3100
+ ]
3101
+ }
3102
+ );
3103
+ }
3104
+
3105
+ // src/components/MarkdownEditor/Toolbar/buttons/FloatingPanel.tsx
3106
+ import { useLayoutEffect, useRef as useRef4, useState as useState4 } from "react";
3107
+ import { createPortal } from "react-dom";
3108
+ import { jsx as jsx7 } from "react/jsx-runtime";
3109
+ function FloatingPanel({
3110
+ anchor,
3111
+ align = "start",
3112
+ autoFocus = false,
3113
+ children
3114
+ }) {
3115
+ const panelRef = useRef4(null);
3116
+ const [style, setStyle] = useState4(null);
3117
+ useLayoutEffect(() => {
3118
+ if (!anchor) return;
3119
+ const rect = anchor.getBoundingClientRect();
3120
+ if (align === "end") {
3121
+ setStyle({
3122
+ top: rect.bottom,
3123
+ right: Math.max(0, window.innerWidth - rect.right)
3124
+ });
3125
+ } else {
3126
+ setStyle({ top: rect.bottom, left: rect.left });
3127
+ }
3128
+ }, [anchor, align]);
3129
+ useLayoutEffect(() => {
3130
+ if (style === null || !autoFocus) return;
3131
+ panelRef.current?.querySelector(
3132
+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
3133
+ )?.focus();
3134
+ }, [style !== null]);
3135
+ if (style === null) return null;
3136
+ return createPortal(
3137
+ /* @__PURE__ */ jsx7(
3138
+ "div",
3139
+ {
3140
+ ref: panelRef,
3141
+ className: MarkdownEditor_default["root"],
3142
+ style: {
3143
+ position: "fixed",
3144
+ top: style.top,
3145
+ left: style.left,
3146
+ right: style.right,
3147
+ zIndex: 1e3,
3148
+ // El wrapper solo restablece las custom properties/tipografía del
3149
+ // componente para el contenido portado; no debe verse como una caja.
3150
+ border: "none",
3151
+ overflow: "visible",
3152
+ background: "transparent",
3153
+ width: "auto",
3154
+ height: "auto"
3155
+ },
3156
+ children
3157
+ }
3158
+ ),
3159
+ document.body
3160
+ );
3161
+ }
3162
+
3163
+ // src/components/MarkdownEditor/Toolbar/buttons/ExportMenu.tsx
3164
+ import { useRef as useRef5, useState as useState5 } from "react";
3165
+
3166
+ // src/components/MarkdownEditor/Toolbar/buttons/icons.tsx
3167
+ import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
3168
+ var base = { viewBox: "0 0 24 24", "aria-hidden": true };
3169
+ function IconCode(props) {
3170
+ return /* @__PURE__ */ jsxs4("svg", { ...base, ...props, children: [
3171
+ /* @__PURE__ */ jsx8("path", { d: "M9 7L4 12L9 17" }),
3172
+ /* @__PURE__ */ jsx8("path", { d: "M15 7L20 12L15 17" }),
3173
+ /* @__PURE__ */ jsx8("path", { d: "M14 4L10 20" })
3174
+ ] });
3175
+ }
3176
+ function IconCodeBlock(props) {
3177
+ return /* @__PURE__ */ jsxs4("svg", { ...base, ...props, children: [
3178
+ /* @__PURE__ */ jsx8("path", { d: "M8 6L3 12L8 18" }),
3179
+ /* @__PURE__ */ jsx8("path", { d: "M16 6L21 12L16 18" })
3180
+ ] });
3181
+ }
3182
+ function IconBullets(props) {
3183
+ return /* @__PURE__ */ jsxs4("svg", { ...base, ...props, children: [
3184
+ /* @__PURE__ */ jsx8("circle", { cx: "4", cy: "6", r: "1" }),
3185
+ /* @__PURE__ */ jsx8("circle", { cx: "4", cy: "12", r: "1" }),
3186
+ /* @__PURE__ */ jsx8("circle", { cx: "4", cy: "18", r: "1" }),
3187
+ /* @__PURE__ */ jsx8("path", { d: "M9 6H21" }),
3188
+ /* @__PURE__ */ jsx8("path", { d: "M9 12H21" }),
3189
+ /* @__PURE__ */ jsx8("path", { d: "M9 18H21" })
3190
+ ] });
3191
+ }
3192
+ function IconNumbered(props) {
3193
+ return /* @__PURE__ */ jsxs4("svg", { ...base, ...props, children: [
3194
+ /* @__PURE__ */ jsx8("path", { d: "M4 5H5V9" }),
3195
+ /* @__PURE__ */ jsx8("path", { d: "M3 9H6" }),
3196
+ /* @__PURE__ */ jsx8("path", { d: "M3 13H6" }),
3197
+ /* @__PURE__ */ jsx8("path", { d: "M3 17C3 15 6 15 6 17C6 19 3 19 3 19H6" }),
3198
+ /* @__PURE__ */ jsx8("path", { d: "M10 6H21" }),
3199
+ /* @__PURE__ */ jsx8("path", { d: "M10 12H21" }),
3200
+ /* @__PURE__ */ jsx8("path", { d: "M10 18H21" })
3201
+ ] });
3202
+ }
3203
+ function IconChecklist(props) {
3204
+ return /* @__PURE__ */ jsxs4("svg", { ...base, ...props, children: [
3205
+ /* @__PURE__ */ jsx8("rect", { x: "3", y: "3", width: "6", height: "6" }),
3206
+ /* @__PURE__ */ jsx8("path", { d: "M4 6L6 8L9 4" }),
3207
+ /* @__PURE__ */ jsx8("path", { d: "M12 6H21" }),
3208
+ /* @__PURE__ */ jsx8("rect", { x: "3", y: "14", width: "6", height: "6" }),
3209
+ /* @__PURE__ */ jsx8("path", { d: "M12 17H21" })
3210
+ ] });
3211
+ }
3212
+ function IconIndent(props) {
3213
+ return /* @__PURE__ */ jsxs4("svg", { ...base, ...props, children: [
3214
+ /* @__PURE__ */ jsx8("path", { d: "M3 6H21" }),
3215
+ /* @__PURE__ */ jsx8("path", { d: "M11 12H21" }),
3216
+ /* @__PURE__ */ jsx8("path", { d: "M3 18H21" }),
3217
+ /* @__PURE__ */ jsx8("path", { d: "M3 9.5L6 12L3 14.5" })
3218
+ ] });
3219
+ }
3220
+ function IconOutdent(props) {
3221
+ return /* @__PURE__ */ jsxs4("svg", { ...base, ...props, children: [
3222
+ /* @__PURE__ */ jsx8("path", { d: "M3 6H21" }),
3223
+ /* @__PURE__ */ jsx8("path", { d: "M11 12H21" }),
3224
+ /* @__PURE__ */ jsx8("path", { d: "M3 18H21" }),
3225
+ /* @__PURE__ */ jsx8("path", { d: "M6 9.5L3 12L6 14.5" })
3226
+ ] });
3227
+ }
3228
+ function IconQuote(props) {
3229
+ return /* @__PURE__ */ jsxs4("svg", { ...base, ...props, children: [
3230
+ /* @__PURE__ */ jsx8("path", { d: "M7 8H4V12H8V8C8 5 6 4 4 4" }),
3231
+ /* @__PURE__ */ jsx8("path", { d: "M17 8H14V12H18V8C18 5 16 4 14 4" })
3232
+ ] });
3233
+ }
3234
+ function IconTable(props) {
3235
+ return /* @__PURE__ */ jsxs4("svg", { ...base, ...props, children: [
3236
+ /* @__PURE__ */ jsx8("rect", { x: "3", y: "4", width: "18", height: "16" }),
3237
+ /* @__PURE__ */ jsx8("path", { d: "M3 10H21" }),
3238
+ /* @__PURE__ */ jsx8("path", { d: "M3 15H21" }),
3239
+ /* @__PURE__ */ jsx8("path", { d: "M9 4V20" }),
3240
+ /* @__PURE__ */ jsx8("path", { d: "M15 4V20" })
3241
+ ] });
3242
+ }
3243
+ function IconLink(props) {
3244
+ return /* @__PURE__ */ jsxs4("svg", { ...base, ...props, children: [
3245
+ /* @__PURE__ */ jsx8("path", { d: "M10 13C11.5 14.5 14 14.5 15.5 13L18 10.5C20 8.5 20 5.5 18 3.5C16 1.5 13 1.5 11 3.5L9.5 5" }),
3246
+ /* @__PURE__ */ jsx8("path", { d: "M14 11C12.5 9.5 10 9.5 8.5 11L6 13.5C4 15.5 4 18.5 6 20.5C8 22.5 11 22.5 13 20.5L14.5 19" })
3247
+ ] });
3248
+ }
3249
+ function IconImage(props) {
3250
+ return /* @__PURE__ */ jsxs4("svg", { ...base, ...props, children: [
3251
+ /* @__PURE__ */ jsx8("rect", { x: "3", y: "4", width: "18", height: "16" }),
3252
+ /* @__PURE__ */ jsx8("circle", { cx: "8", cy: "9", r: "2" }),
3253
+ /* @__PURE__ */ jsx8("path", { d: "M3 17L8 12L12 16L15 13L21 19" })
3254
+ ] });
3255
+ }
3256
+ function IconHr(props) {
3257
+ return /* @__PURE__ */ jsxs4("svg", { ...base, ...props, children: [
3258
+ /* @__PURE__ */ jsx8("path", { d: "M3 12H21" }),
3259
+ /* @__PURE__ */ jsx8("path", { d: "M6 6H18", opacity: "0.35" }),
3260
+ /* @__PURE__ */ jsx8("path", { d: "M6 18H18", opacity: "0.35" })
3261
+ ] });
3262
+ }
3263
+ function IconDownload(props) {
3264
+ return /* @__PURE__ */ jsxs4("svg", { ...base, ...props, children: [
3265
+ /* @__PURE__ */ jsx8("path", { d: "M12 3V15" }),
3266
+ /* @__PURE__ */ jsx8("path", { d: "M7 10L12 15L17 10" }),
3267
+ /* @__PURE__ */ jsx8("path", { d: "M4 19H20" })
3268
+ ] });
3269
+ }
3270
+
3271
+ // src/components/MarkdownEditor/Toolbar/buttons/ExportMenu.tsx
3272
+ import { Fragment, jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
3273
+ function ExportMenu({ source, sanitize }) {
3274
+ const [open, setOpen] = useState5(false);
3275
+ const buttonRef = useRef5(null);
3276
+ const close = () => {
3277
+ setOpen(false);
3278
+ buttonRef.current?.focus();
3279
+ };
3280
+ const copy = (content) => {
3281
+ void navigator.clipboard.writeText(content);
3282
+ close();
3283
+ };
3284
+ return /* @__PURE__ */ jsxs5(Fragment, { children: [
3285
+ /* @__PURE__ */ jsx9(
3286
+ "button",
3287
+ {
3288
+ ref: buttonRef,
3289
+ type: "button",
3290
+ className: MarkdownEditor_default["button"],
3291
+ "aria-label": "Export",
3292
+ title: "Export",
3293
+ "aria-haspopup": "menu",
3294
+ "aria-expanded": open,
3295
+ onClick: () => setOpen((value) => !value),
3296
+ children: /* @__PURE__ */ jsx9(IconDownload, {})
3297
+ }
3298
+ ),
3299
+ open && /* @__PURE__ */ jsx9(FloatingPanel, { anchor: buttonRef.current, align: "end", autoFocus: true, children: /* @__PURE__ */ jsxs5(
3300
+ "div",
3301
+ {
3302
+ role: "menu",
3303
+ "aria-label": "Exportar contenido",
3304
+ className: MarkdownEditor_default["menu"],
3305
+ onKeyDown: (event) => {
3306
+ if (event.key === "Escape") {
3307
+ event.stopPropagation();
3308
+ close();
3309
+ }
3310
+ },
3311
+ children: [
3312
+ /* @__PURE__ */ jsx9(
3313
+ "button",
3314
+ {
3315
+ type: "button",
3316
+ role: "menuitem",
3317
+ className: MarkdownEditor_default["menuItem"],
3318
+ onClick: () => copy(source),
3319
+ children: "Copiar como Markdown"
3320
+ }
3321
+ ),
3322
+ /* @__PURE__ */ jsx9(
3323
+ "button",
3324
+ {
3325
+ type: "button",
3326
+ role: "menuitem",
3327
+ className: MarkdownEditor_default["menuItem"],
3328
+ onClick: () => copy(markdownToHtml(source, { sanitize })),
3329
+ children: "Copiar como HTML"
3330
+ }
3331
+ )
3332
+ ]
3333
+ }
3334
+ ) })
3335
+ ] });
3336
+ }
3337
+
3338
+ // src/components/MarkdownEditor/Toolbar/buttons/Separator.tsx
3339
+ import { jsx as jsx10 } from "react/jsx-runtime";
3340
+ function Separator() {
3341
+ return /* @__PURE__ */ jsx10("span", { className: MarkdownEditor_default["separator"], "aria-hidden": "true" });
3342
+ }
3343
+
3344
+ // src/components/MarkdownEditor/Toolbar/Toolbar.tsx
3345
+ import { jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
3346
+ var HEADING_LEVELS = [1, 2, 3, 4, 5, 6];
3347
+ function Toolbar({
3348
+ editor,
3349
+ viewMode,
3350
+ onToggleView,
3351
+ source,
3352
+ sanitizeEmbeddedHtml,
3353
+ onlyView = false
3354
+ }) {
3355
+ const [, forceUpdate] = useReducer((count) => count + 1, 0);
3356
+ const [openDialog, setOpenDialog] = useState6(null);
3357
+ const [anchor, setAnchor] = useState6(null);
3358
+ const openDialogAt = (kind, event) => {
3359
+ setAnchor(event.currentTarget);
3360
+ setOpenDialog(kind);
3361
+ };
3362
+ useEffect4(() => {
3363
+ if (!editor) return;
3364
+ editor.on("transaction", forceUpdate);
3365
+ return () => {
3366
+ editor.off("transaction", forceUpdate);
3367
+ };
3368
+ }, [editor]);
3369
+ if (onlyView) {
3370
+ return /* @__PURE__ */ jsxs6(
3371
+ "div",
3372
+ {
3373
+ role: "toolbar",
3374
+ "aria-label": "Barra de herramientas",
3375
+ className: MarkdownEditor_default["toolbar"],
3376
+ children: [
3377
+ /* @__PURE__ */ jsx11("span", { className: MarkdownEditor_default["readOnlyNotice"], children: "Edici\xF3n desactivada" }),
3378
+ /* @__PURE__ */ jsx11("div", { className: MarkdownEditor_default["spacer"], children: /* @__PURE__ */ jsx11(ExportMenu, { source, sanitize: sanitizeEmbeddedHtml }) })
3379
+ ]
3380
+ }
3381
+ );
3382
+ }
3383
+ const canFormat = viewMode === "wysiwyg" && editor !== null;
3384
+ const activeHeading = canFormat ? HEADING_LEVELS.find(
3385
+ (level) => editor.isActive("heading", { level })
3386
+ ) ?? null : null;
3387
+ const listItemType = canFormat && editor.isActive("taskItem") ? "taskItem" : "listItem";
3388
+ const closeDialog = () => setOpenDialog(null);
3389
+ return /* @__PURE__ */ jsxs6(
3390
+ "div",
3391
+ {
3392
+ role: "toolbar",
3393
+ "aria-label": "Barra de herramientas",
3394
+ className: MarkdownEditor_default["toolbar"],
3395
+ children: [
3396
+ /* @__PURE__ */ jsx11(
3397
+ ToolbarButton,
3398
+ {
3399
+ label: "Ver c\xF3digo Markdown",
3400
+ pressed: viewMode === "markdown",
3401
+ onClick: onToggleView,
3402
+ children: /* @__PURE__ */ jsx11(IconCode, {})
3403
+ }
3404
+ ),
3405
+ /* @__PURE__ */ jsxs6(
3406
+ "select",
3407
+ {
3408
+ className: MarkdownEditor_default["headingSelect"],
3409
+ "aria-label": "Nivel de encabezado",
3410
+ disabled: !canFormat,
3411
+ value: activeHeading === null ? "p" : `h${activeHeading}`,
3412
+ onChange: (event) => {
3413
+ if (!editor) return;
3414
+ const value = event.target.value;
3415
+ if (value === "p") {
3416
+ editor.chain().focus().setParagraph().run();
3417
+ } else {
3418
+ const level = Number(value.slice(1));
3419
+ editor.chain().focus().setHeading({ level }).run();
3420
+ }
3421
+ },
3422
+ children: [
3423
+ /* @__PURE__ */ jsx11("option", { value: "p", children: "P\xE1rrafo" }),
3424
+ HEADING_LEVELS.map((level) => /* @__PURE__ */ jsxs6("option", { value: `h${level}`, children: [
3425
+ "Encabezado ",
3426
+ level
3427
+ ] }, level))
3428
+ ]
3429
+ }
3430
+ ),
3431
+ /* @__PURE__ */ jsx11(
3432
+ ToolbarButton,
3433
+ {
3434
+ label: "Negrita",
3435
+ className: MarkdownEditor_default["boldGlyph"],
3436
+ disabled: !canFormat,
3437
+ pressed: canFormat && editor.isActive("bold"),
3438
+ onClick: () => editor?.chain().focus().toggleBold().run(),
3439
+ children: "B"
3440
+ }
3441
+ ),
3442
+ /* @__PURE__ */ jsx11(
3443
+ ToolbarButton,
3444
+ {
3445
+ label: "Cursiva",
3446
+ className: MarkdownEditor_default["italicGlyph"],
3447
+ disabled: !canFormat,
3448
+ pressed: canFormat && editor.isActive("italic"),
3449
+ onClick: () => editor?.chain().focus().toggleItalic().run(),
3450
+ children: "i"
3451
+ }
3452
+ ),
3453
+ /* @__PURE__ */ jsx11(
3454
+ ToolbarButton,
3455
+ {
3456
+ label: "Tachado",
3457
+ className: MarkdownEditor_default["strikeGlyph"],
3458
+ disabled: !canFormat,
3459
+ pressed: canFormat && editor.isActive("strike"),
3460
+ onClick: () => editor?.chain().focus().toggleStrike().run(),
3461
+ children: "S"
3462
+ }
3463
+ ),
3464
+ /* @__PURE__ */ jsx11(Separator, {}),
3465
+ /* @__PURE__ */ jsx11(
3466
+ ToolbarButton,
3467
+ {
3468
+ label: "Lista con vi\xF1etas",
3469
+ disabled: !canFormat,
3470
+ pressed: canFormat && editor.isActive("bulletList"),
3471
+ onClick: () => editor?.chain().focus().toggleBulletList().run(),
3472
+ children: /* @__PURE__ */ jsx11(IconBullets, {})
3473
+ }
3474
+ ),
3475
+ /* @__PURE__ */ jsx11(
3476
+ ToolbarButton,
3477
+ {
3478
+ label: "Lista ordenada",
3479
+ disabled: !canFormat,
3480
+ pressed: canFormat && editor.isActive("orderedList"),
3481
+ onClick: () => editor?.chain().focus().toggleOrderedList().run(),
3482
+ children: /* @__PURE__ */ jsx11(IconNumbered, {})
3483
+ }
3484
+ ),
3485
+ /* @__PURE__ */ jsx11(
3486
+ ToolbarButton,
3487
+ {
3488
+ label: "Lista de tareas",
3489
+ disabled: !canFormat,
3490
+ pressed: canFormat && editor.isActive("taskList"),
3491
+ onClick: () => editor?.chain().focus().toggleTaskList().run(),
3492
+ children: /* @__PURE__ */ jsx11(IconChecklist, {})
3493
+ }
3494
+ ),
3495
+ /* @__PURE__ */ jsx11(
3496
+ ToolbarButton,
3497
+ {
3498
+ label: "Aumentar sangr\xEDa",
3499
+ disabled: !canFormat || !editor.can().sinkListItem(listItemType),
3500
+ onClick: () => editor?.chain().focus().sinkListItem(listItemType).run(),
3501
+ children: /* @__PURE__ */ jsx11(IconIndent, {})
3502
+ }
3503
+ ),
3504
+ /* @__PURE__ */ jsx11(
3505
+ ToolbarButton,
3506
+ {
3507
+ label: "Disminuir sangr\xEDa",
3508
+ disabled: !canFormat || !editor.can().liftListItem(listItemType),
3509
+ onClick: () => editor?.chain().focus().liftListItem(listItemType).run(),
3510
+ children: /* @__PURE__ */ jsx11(IconOutdent, {})
3511
+ }
3512
+ ),
3513
+ /* @__PURE__ */ jsx11(Separator, {}),
3514
+ /* @__PURE__ */ jsx11(
3515
+ ToolbarButton,
3516
+ {
3517
+ label: "Bloque de c\xF3digo",
3518
+ disabled: !canFormat,
3519
+ pressed: canFormat && editor.isActive("codeBlock"),
3520
+ onClick: (event) => openDialogAt("codeLanguage", event),
3521
+ children: /* @__PURE__ */ jsx11(IconCodeBlock, {})
3522
+ }
3523
+ ),
3524
+ /* @__PURE__ */ jsx11(
3525
+ ToolbarButton,
3526
+ {
3527
+ label: "Cita",
3528
+ disabled: !canFormat,
3529
+ pressed: canFormat && editor.isActive("blockquote"),
3530
+ onClick: () => editor?.chain().focus().toggleBlockquote().run(),
3531
+ children: /* @__PURE__ */ jsx11(IconQuote, {})
3532
+ }
3533
+ ),
3534
+ /* @__PURE__ */ jsx11(
3535
+ ToolbarButton,
3536
+ {
3537
+ label: "Insertar tabla",
3538
+ disabled: !canFormat,
3539
+ onClick: (event) => openDialogAt("table", event),
3540
+ children: /* @__PURE__ */ jsx11(IconTable, {})
3541
+ }
3542
+ ),
3543
+ /* @__PURE__ */ jsx11(
3544
+ ToolbarButton,
3545
+ {
3546
+ label: "L\xEDnea horizontal",
3547
+ disabled: !canFormat,
3548
+ onClick: () => editor?.chain().focus().setHorizontalRule().run(),
3549
+ children: /* @__PURE__ */ jsx11(IconHr, {})
3550
+ }
3551
+ ),
3552
+ /* @__PURE__ */ jsx11(Separator, {}),
3553
+ /* @__PURE__ */ jsx11(
3554
+ ToolbarButton,
3555
+ {
3556
+ label: "Insertar enlace",
3557
+ disabled: !canFormat,
3558
+ pressed: canFormat && editor.isActive("link"),
3559
+ onClick: (event) => openDialogAt("link", event),
3560
+ children: /* @__PURE__ */ jsx11(IconLink, {})
3561
+ }
3562
+ ),
3563
+ /* @__PURE__ */ jsx11(
3564
+ ToolbarButton,
3565
+ {
3566
+ label: "Insertar imagen",
3567
+ disabled: !canFormat,
3568
+ onClick: (event) => openDialogAt("image", event),
3569
+ children: /* @__PURE__ */ jsx11(IconImage, {})
3570
+ }
3571
+ ),
3572
+ /* @__PURE__ */ jsx11(
3573
+ ToolbarButton,
3574
+ {
3575
+ label: "Insertar HTML",
3576
+ disabled: !canFormat,
3577
+ onClick: (event) => openDialogAt("html", event),
3578
+ children: /* @__PURE__ */ jsx11("span", { className: MarkdownEditor_default["htmlIcon"], children: "HTML" })
3579
+ }
3580
+ ),
3581
+ /* @__PURE__ */ jsx11("div", { className: MarkdownEditor_default["spacer"], children: /* @__PURE__ */ jsx11(ExportMenu, { source, sanitize: sanitizeEmbeddedHtml }) }),
3582
+ openDialog === "table" && editor !== null && /* @__PURE__ */ jsx11(FloatingPanel, { anchor, children: /* @__PURE__ */ jsx11(
3583
+ TableSizePicker,
3584
+ {
3585
+ onSelect: ({ cols, rows }) => {
3586
+ editor.chain().focus().insertTable({ rows, cols, withHeaderRow: true }).run();
3587
+ closeDialog();
3588
+ },
3589
+ onClose: closeDialog
3590
+ }
3591
+ ) }),
3592
+ openDialog === "codeLanguage" && editor !== null && /* @__PURE__ */ jsx11(FloatingPanel, { anchor, children: /* @__PURE__ */ jsx11(
3593
+ CodeLanguagePicker,
3594
+ {
3595
+ currentLanguage: editor.getAttributes("codeBlock")["language"] ?? null,
3596
+ onSelect: (language) => {
3597
+ if (editor.isActive("codeBlock")) {
3598
+ editor.chain().focus().updateAttributes("codeBlock", { language }).run();
3599
+ } else {
3600
+ editor.chain().focus().toggleCodeBlock({ language }).run();
3601
+ }
3602
+ closeDialog();
3603
+ },
3604
+ onClose: closeDialog
3605
+ }
3606
+ ) }),
3607
+ openDialog !== null && openDialog !== "table" && openDialog !== "codeLanguage" && editor !== null && /* @__PURE__ */ jsx11(FloatingPanel, { anchor, children: /* @__PURE__ */ jsx11(
3608
+ InsertDialog,
3609
+ {
3610
+ kind: openDialog,
3611
+ editor,
3612
+ onClose: closeDialog
3613
+ }
3614
+ ) })
3615
+ ]
3616
+ }
3617
+ );
3618
+ }
3619
+
3620
+ // src/components/MarkdownEditor/Toolbar/buttons/LinkPopover.tsx
3621
+ import { useEffect as useEffect5, useId as useId3, useRef as useRef6, useState as useState7 } from "react";
3622
+ import { Fragment as Fragment2, jsx as jsx12, jsxs as jsxs7 } from "react/jsx-runtime";
3623
+ function LinkPopover({
3624
+ url,
3625
+ onlyView,
3626
+ onNavigate,
3627
+ onCopy,
3628
+ onSave,
3629
+ onRemove,
3630
+ onClose
3631
+ }) {
3632
+ const [mode, setMode] = useState7("menu");
3633
+ const [inputValue, setInputValue] = useState7(url);
3634
+ const rootRef = useRef6(null);
3635
+ const inputId = useId3();
3636
+ useEffect5(() => {
3637
+ if (mode === "edit") {
3638
+ rootRef.current?.querySelector("input")?.focus();
3639
+ }
3640
+ }, [mode]);
3641
+ useEffect5(() => {
3642
+ const handlePointerDown = (event) => {
3643
+ if (rootRef.current !== null && !rootRef.current.contains(event.target)) {
3644
+ onClose();
3645
+ }
3646
+ };
3647
+ document.addEventListener("pointerdown", handlePointerDown);
3648
+ return () => {
3649
+ document.removeEventListener("pointerdown", handlePointerDown);
3650
+ };
3651
+ }, [onClose]);
3652
+ const handleKeyDown = (event) => {
3653
+ if (event.key === "Escape") {
3654
+ event.stopPropagation();
3655
+ onClose();
3656
+ }
3657
+ };
3658
+ const save = () => {
3659
+ if (!inputValue) return;
3660
+ onSave(ensureProtocol(inputValue));
3661
+ };
3662
+ if (mode === "edit") {
3663
+ return /* @__PURE__ */ jsxs7(
3664
+ "div",
3665
+ {
3666
+ ref: rootRef,
3667
+ className: MarkdownEditor_default["dialog"],
3668
+ role: "dialog",
3669
+ "aria-label": "Editar enlace",
3670
+ onKeyDown: handleKeyDown,
3671
+ children: [
3672
+ /* @__PURE__ */ jsxs7("div", { className: MarkdownEditor_default["dialogField"], children: [
3673
+ /* @__PURE__ */ jsx12("label", { htmlFor: inputId, children: "URL del enlace" }),
3674
+ /* @__PURE__ */ jsx12(
3675
+ "input",
3676
+ {
3677
+ id: inputId,
3678
+ type: "text",
3679
+ value: inputValue,
3680
+ onChange: (event) => setInputValue(event.target.value)
3681
+ }
3682
+ )
3683
+ ] }),
3684
+ /* @__PURE__ */ jsx12(
3685
+ "button",
3686
+ {
3687
+ type: "button",
3688
+ className: MarkdownEditor_default["dangerLink"],
3689
+ onClick: onRemove,
3690
+ children: "Eliminar link"
3691
+ }
3692
+ ),
3693
+ /* @__PURE__ */ jsx12("div", { className: MarkdownEditor_default["dialogActions"], children: /* @__PURE__ */ jsx12(
3694
+ "button",
3695
+ {
3696
+ type: "button",
3697
+ className: `${MarkdownEditor_default["button"]} ${MarkdownEditor_default["textButton"]}`,
3698
+ onClick: save,
3699
+ children: "Guardar"
3700
+ }
3701
+ ) })
3702
+ ]
3703
+ }
3704
+ );
3705
+ }
3706
+ return /* @__PURE__ */ jsxs7(
3707
+ "div",
3708
+ {
3709
+ ref: rootRef,
3710
+ role: "menu",
3711
+ "aria-label": "Acciones del enlace",
3712
+ className: MarkdownEditor_default["menu"],
3713
+ onKeyDown: handleKeyDown,
3714
+ children: [
3715
+ /* @__PURE__ */ jsx12(
3716
+ "button",
3717
+ {
3718
+ type: "button",
3719
+ role: "menuitem",
3720
+ className: MarkdownEditor_default["menuItem"],
3721
+ onClick: onNavigate,
3722
+ children: "Ir a la url"
3723
+ }
3724
+ ),
3725
+ /* @__PURE__ */ jsx12(
3726
+ "button",
3727
+ {
3728
+ type: "button",
3729
+ role: "menuitem",
3730
+ className: MarkdownEditor_default["menuItem"],
3731
+ onClick: onCopy,
3732
+ children: "Copiar url"
3733
+ }
3734
+ ),
3735
+ !onlyView && /* @__PURE__ */ jsxs7(Fragment2, { children: [
3736
+ /* @__PURE__ */ jsx12("hr", { className: MarkdownEditor_default["menuSeparator"] }),
3737
+ /* @__PURE__ */ jsx12(
3738
+ "button",
3739
+ {
3740
+ type: "button",
3741
+ role: "menuitem",
3742
+ className: MarkdownEditor_default["menuItem"],
3743
+ onClick: () => setMode("edit"),
3744
+ children: "Editar url"
3745
+ }
3746
+ )
3747
+ ] })
3748
+ ]
3749
+ }
3750
+ );
3751
+ }
3752
+
3753
+ // src/components/MarkdownEditor/MarkdownEditor.tsx
3754
+ import { jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
3755
+ function toCssSize(value) {
3756
+ return typeof value === "number" ? `${value}px` : value;
3757
+ }
3758
+ function MarkdownEditor({
3759
+ initialContent = "",
3760
+ onChange,
3761
+ width = 700,
3762
+ height = 500,
3763
+ sanitizeEmbeddedHtml = true,
3764
+ className,
3765
+ onlyView = false,
3766
+ resizable = true
3767
+ }) {
3768
+ const [source, setSource] = useState8(initialContent);
3769
+ const [viewMode, setViewMode] = useState8("wysiwyg");
3770
+ const effectiveViewMode = onlyView ? "wysiwyg" : viewMode;
3771
+ const [linkPopover, setLinkPopover] = useState8(
3772
+ null
3773
+ );
3774
+ const onChangeRef = useRef7(onChange);
3775
+ onChangeRef.current = onChange;
3776
+ const sourceRef = useRef7(source);
3777
+ sourceRef.current = source;
3778
+ const extensions = useMemo(
3779
+ () => createEditorExtensions({ sanitizeEmbeddedHtml }),
3780
+ [sanitizeEmbeddedHtml]
3781
+ );
3782
+ const editor = useEditor(
3783
+ {
3784
+ extensions,
3785
+ content: markdownToEditorContent(sourceRef.current),
3786
+ editable: !onlyView,
3787
+ editorProps: {
3788
+ attributes: {
3789
+ role: "textbox",
3790
+ "aria-multiline": "true",
3791
+ "aria-label": "Editor de texto enriquecido"
3792
+ },
3793
+ handleDOMEvents: {
3794
+ click(view, event) {
3795
+ const target = event.target;
3796
+ if (!(target instanceof Element)) return false;
3797
+ const anchorEl = target.closest("a");
3798
+ if (anchorEl === null || !view.dom.contains(anchorEl)) {
3799
+ return false;
3800
+ }
3801
+ const linkType = view.state.schema.marks["link"];
3802
+ if (!linkType) return false;
3803
+ const pos = view.posAtDOM(anchorEl, 0);
3804
+ const $pos = view.state.doc.resolve(
3805
+ Math.min(pos + 1, view.state.doc.content.size)
3806
+ );
3807
+ const range = getMarkRange($pos, linkType);
3808
+ if (!range) return false;
3809
+ const mark = $pos.marks().find((candidate) => candidate.type === linkType);
3810
+ const href = mark?.attrs["href"];
3811
+ if (href === void 0) return false;
3812
+ event.preventDefault();
3813
+ setLinkPopover({ url: href, range, anchor: anchorEl });
3814
+ return true;
3815
+ }
3816
+ }
3817
+ },
3818
+ onUpdate({ editor: currentEditor }) {
3819
+ const markdown = editorToMarkdown(currentEditor);
3820
+ sourceRef.current = markdown;
3821
+ setSource(markdown);
3822
+ onChangeRef.current?.(markdown);
3823
+ }
3824
+ },
3825
+ [sanitizeEmbeddedHtml, onlyView]
3826
+ );
3827
+ const toggleView = () => {
3828
+ if (viewMode === "wysiwyg") {
3829
+ setViewMode("markdown");
3830
+ } else {
3831
+ editor?.commands.setContent(
3832
+ markdownToEditorContent(sourceRef.current),
3833
+ false
3834
+ );
3835
+ setViewMode("wysiwyg");
3836
+ }
3837
+ };
3838
+ const handleSourceChange = (value) => {
3839
+ sourceRef.current = value;
3840
+ setSource(value);
3841
+ onChangeRef.current?.(value);
3842
+ };
3843
+ const closeLinkPopover = () => setLinkPopover(null);
3844
+ const saveLinkPopover = (newUrl) => {
3845
+ if (!editor || !linkPopover) return;
3846
+ editor.chain().focus().setTextSelection(linkPopover.range).extendMarkRange("link").setLink({ href: newUrl }).run();
3847
+ closeLinkPopover();
3848
+ };
3849
+ const removeLinkPopover = () => {
3850
+ if (!editor || !linkPopover) return;
3851
+ editor.chain().focus().setTextSelection(linkPopover.range).extendMarkRange("link").unsetLink().run();
3852
+ closeLinkPopover();
3853
+ };
3854
+ const rootClassName = [
3855
+ MarkdownEditor_default["root"],
3856
+ resizable ? MarkdownEditor_default["resizable"] : void 0,
3857
+ className
3858
+ ].filter(Boolean).join(" ");
3859
+ return /* @__PURE__ */ jsxs8(
3860
+ "div",
3861
+ {
3862
+ className: rootClassName,
3863
+ style: { width: toCssSize(width), height: toCssSize(height) },
3864
+ children: [
3865
+ /* @__PURE__ */ jsx13(
3866
+ Toolbar,
3867
+ {
3868
+ editor,
3869
+ viewMode: effectiveViewMode,
3870
+ onToggleView: toggleView,
3871
+ source,
3872
+ sanitizeEmbeddedHtml,
3873
+ onlyView
3874
+ }
3875
+ ),
3876
+ /* @__PURE__ */ jsx13("div", { className: MarkdownEditor_default["content"], children: effectiveViewMode === "wysiwyg" ? /* @__PURE__ */ jsx13(RenderedView, { editor }) : /* @__PURE__ */ jsx13(
3877
+ MarkdownSourceView,
3878
+ {
3879
+ value: source,
3880
+ onChange: handleSourceChange,
3881
+ readOnly: onlyView
3882
+ }
3883
+ ) }),
3884
+ linkPopover !== null && /* @__PURE__ */ jsx13(FloatingPanel, { anchor: linkPopover.anchor, autoFocus: true, children: /* @__PURE__ */ jsx13(
3885
+ LinkPopover,
3886
+ {
3887
+ url: linkPopover.url,
3888
+ onlyView,
3889
+ onNavigate: () => {
3890
+ window.open(linkPopover.url, "_blank", "noopener,noreferrer");
3891
+ closeLinkPopover();
3892
+ },
3893
+ onCopy: () => {
3894
+ void navigator.clipboard.writeText(linkPopover.url);
3895
+ closeLinkPopover();
3896
+ },
3897
+ onSave: saveLinkPopover,
3898
+ onRemove: removeLinkPopover,
3899
+ onClose: closeLinkPopover
3900
+ }
3901
+ ) })
3902
+ ]
3903
+ }
3904
+ );
3905
+ }
3906
+ export {
3907
+ MarkdownEditor
3908
+ };
3909
+ //# sourceMappingURL=index.js.map