pro-editor-schema 0.1.1 → 0.1.13

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.mjs CHANGED
@@ -1,16 +1,16 @@
1
1
  // src/schema/utils/createSchema.ts
2
2
  var createSchema = ({
3
+ code,
3
4
  kind,
4
5
  tag,
5
- role,
6
6
  requiredAttributes,
7
7
  optionalAttributes,
8
8
  allowedChildTagNames
9
9
  }) => {
10
10
  return {
11
+ code,
11
12
  kind,
12
13
  tag,
13
- role,
14
14
  requiredAttributes,
15
15
  optionalAttributes,
16
16
  allowedChildTagNames: new Set(allowedChildTagNames)
@@ -92,6 +92,7 @@ var ATOM_TAGS_ALLOWED_CHILDREN = [
92
92
 
93
93
  // src/schema/elementSchemas/atoms/b.ts
94
94
  var B_SCHEMA = createSchema({
95
+ code: "b",
95
96
  kind: "atom",
96
97
  tag: B_TAG,
97
98
  requiredAttributes: [...ID_ATTRS],
@@ -99,21 +100,11 @@ var B_SCHEMA = createSchema({
99
100
  allowedChildTagNames: [...ATOM_TAGS_ALLOWED_CHILDREN]
100
101
  });
101
102
 
102
- // src/schema/schema.types.ts
103
- var ELEMENT_ROLE = /* @__PURE__ */ ((ELEMENT_ROLE2) => {
104
- ELEMENT_ROLE2["QUERYCOMMENTSWRAPPER"] = "QUERYCOMMENTSWRAPPER";
105
- ELEMENT_ROLE2["HEADING"] = "HEADING";
106
- ELEMENT_ROLE2["FOOTNOTE"] = "FOOTNOTE";
107
- ELEMENT_ROLE2["INS"] = "INS";
108
- ELEMENT_ROLE2["DEL"] = "DEL";
109
- return ELEMENT_ROLE2;
110
- })(ELEMENT_ROLE || {});
111
-
112
103
  // src/schema/elementSchemas/atoms/commentQuerySection.ts
113
104
  var COMMENT_QUERY_SECTION_SCHEMA = createSchema({
114
105
  kind: "atom",
115
106
  tag: SPAN_TAG,
116
- role: "QUERYCOMMENTSWRAPPER" /* QUERYCOMMENTSWRAPPER */,
107
+ code: "commentQuerySection",
117
108
  requiredAttributes: [...ID_ATTRS, "id"],
118
109
  optionalAttributes: [...TRACK_CHANGES_ATTRS, "title"],
119
110
  allowedChildTagNames: [...ATOM_TAGS_ALLOWED_CHILDREN]
@@ -122,7 +113,7 @@ var COMMENT_QUERY_SECTION_SCHEMA = createSchema({
122
113
  // src/schema/elementSchemas/inlineElements/inlineElementsTags.ts
123
114
  var FOOTNOTE_LINK_TAG = "FOOTNOTE1";
124
115
  var INLINEEQUATION_TAG = "INLINEEQUATION";
125
- var LINK_TAG = "LINK";
116
+ var LINK_TAG = "LINK1";
126
117
  var URI_TAG = "URI";
127
118
  var INLINE_ELEMENT_TAGS_ALLOWED_CHILDREN = [
128
119
  { tagName: FOOTNOTE_LINK_TAG, required: false },
@@ -133,9 +124,9 @@ var INLINE_ELEMENT_TAGS_ALLOWED_CHILDREN = [
133
124
 
134
125
  // src/schema/elementSchemas/atoms/deletion.ts
135
126
  var DELETION_SCHEMA = createSchema({
127
+ code: "deletion",
136
128
  kind: "atom",
137
129
  tag: SPAN_TAG,
138
- role: "DEL" /* DEL */,
139
130
  requiredAttributes: [...TRACK_CHANGES_ATTRS, ...ID_ATTRS],
140
131
  optionalAttributes: [],
141
132
  allowedChildTagNames: [
@@ -146,6 +137,7 @@ var DELETION_SCHEMA = createSchema({
146
137
 
147
138
  // src/schema/elementSchemas/atoms/emphasis.ts
148
139
  var EMPHASIS_SCHEMA = createSchema({
140
+ code: "emphasis",
149
141
  kind: "atom",
150
142
  tag: EMPHASIS_TAG,
151
143
  requiredAttributes: [...ID_ATTRS],
@@ -162,6 +154,7 @@ var EMPHASIS_SCHEMA = createSchema({
162
154
 
163
155
  // src/schema/elementSchemas/atoms/highlightmark.ts
164
156
  var HIGHLIGHTMARK_SCHEMA = createSchema({
157
+ code: "highlightmark",
165
158
  kind: "atom",
166
159
  tag: HIGHLIGHTMARK_TAG,
167
160
  requiredAttributes: [...ID_ATTRS],
@@ -171,6 +164,7 @@ var HIGHLIGHTMARK_SCHEMA = createSchema({
171
164
 
172
165
  // src/schema/elementSchemas/atoms/i.ts
173
166
  var I_SCHEMA = createSchema({
167
+ code: "i",
174
168
  kind: "atom",
175
169
  tag: I_TAG,
176
170
  requiredAttributes: [...ID_ATTRS],
@@ -180,9 +174,9 @@ var I_SCHEMA = createSchema({
180
174
 
181
175
  // src/schema/elementSchemas/atoms/insertion.ts
182
176
  var INSERTION_SCHEMA = createSchema({
177
+ code: "insertion",
183
178
  kind: "atom",
184
179
  tag: SPAN_TAG,
185
- role: "INS" /* INS */,
186
180
  requiredAttributes: [...TRACK_CHANGES_ATTRS, ...ID_ATTRS],
187
181
  optionalAttributes: [],
188
182
  allowedChildTagNames: [
@@ -193,6 +187,7 @@ var INSERTION_SCHEMA = createSchema({
193
187
 
194
188
  // src/schema/elementSchemas/atoms/sc.ts
195
189
  var SC_SCHEMA = createSchema({
190
+ code: "sc",
196
191
  kind: "atom",
197
192
  tag: SC_TAG,
198
193
  requiredAttributes: [...ID_ATTRS],
@@ -202,6 +197,7 @@ var SC_SCHEMA = createSchema({
202
197
 
203
198
  // src/schema/elementSchemas/atoms/strike.ts
204
199
  var STRIKE_SCHEMA = createSchema({
200
+ code: "strike",
205
201
  kind: "atom",
206
202
  tag: STRIKE_TAG,
207
203
  requiredAttributes: [...ID_ATTRS],
@@ -211,6 +207,7 @@ var STRIKE_SCHEMA = createSchema({
211
207
 
212
208
  // src/schema/elementSchemas/atoms/sub.ts
213
209
  var SUB_SCHEMA = createSchema({
210
+ code: "sub",
214
211
  kind: "atom",
215
212
  tag: SUB_TAG,
216
213
  requiredAttributes: [...ID_ATTRS],
@@ -220,6 +217,7 @@ var SUB_SCHEMA = createSchema({
220
217
 
221
218
  // src/schema/elementSchemas/atoms/sup.ts
222
219
  var SUP_SCHEMA = createSchema({
220
+ code: "sup",
223
221
  kind: "atom",
224
222
  tag: SUP_TAG,
225
223
  requiredAttributes: [...ID_ATTRS],
@@ -229,6 +227,7 @@ var SUP_SCHEMA = createSchema({
229
227
 
230
228
  // src/schema/elementSchemas/atoms/u.ts
231
229
  var U_SCHEMA = createSchema({
230
+ code: "u",
232
231
  kind: "atom",
233
232
  tag: U_TAG,
234
233
  requiredAttributes: [...ID_ATTRS],
@@ -238,6 +237,7 @@ var U_SCHEMA = createSchema({
238
237
 
239
238
  // src/schema/elementSchemas/atoms/content.ts
240
239
  var CONTENT_SCHEMA = createSchema({
240
+ code: "content",
241
241
  kind: "inline",
242
242
  tag: CONTENT_TAG,
243
243
  requiredAttributes: [...ID_ATTRS],
@@ -256,6 +256,7 @@ var CONTENT_SCHEMA = createSchema({
256
256
 
257
257
  // src/schema/elementSchemas/atoms/comment.ts
258
258
  var COMMENT_SCHEMA = createSchema({
259
+ code: "comment",
259
260
  kind: "inline",
260
261
  tag: COMMENT_TAG,
261
262
  requiredAttributes: [...ID_ATTRS, "id"],
@@ -278,6 +279,7 @@ var COMMENT_SCHEMA = createSchema({
278
279
 
279
280
  // src/schema/elementSchemas/atoms/query.ts
280
281
  var QUERY_SCHEMA = createSchema({
282
+ code: "query",
281
283
  kind: "inline",
282
284
  tag: QUERY_TAG,
283
285
  requiredAttributes: [...ID_ATTRS, "id"],
@@ -300,6 +302,7 @@ var QUERY_SCHEMA = createSchema({
300
302
 
301
303
  // src/schema/elementSchemas/atoms/reply.ts
302
304
  var REPLY_SCHEMA = createSchema({
305
+ code: "reply",
303
306
  kind: "inline",
304
307
  tag: REPLY_TAG,
305
308
  requiredAttributes: [...ID_ATTRS, "id"],
@@ -471,6 +474,7 @@ var GROUP_ELEMENTS_TAGS = [
471
474
 
472
475
  // src/schema/elementSchemas/elements/authors/authorgroup.ts
473
476
  var AUTHORGROUP_SCHEMA = createSchema({
477
+ code: "authorgroup",
474
478
  kind: "group",
475
479
  tag: AUTHORGROUP_TAG,
476
480
  requiredAttributes: [...ID_ATTRS],
@@ -483,6 +487,7 @@ var AUTHORGROUP_SCHEMA = createSchema({
483
487
 
484
488
  // src/schema/elementSchemas/elements/authors/author.ts
485
489
  var AUTHOR_SCHEMA = createSchema({
490
+ code: "author",
486
491
  kind: "group",
487
492
  tag: AUTHOR_TAG,
488
493
  requiredAttributes: [...ID_ATTRS],
@@ -499,6 +504,7 @@ var AUTHOR_SCHEMA = createSchema({
499
504
 
500
505
  // src/schema/elementSchemas/elements/authors/olink.ts
501
506
  var OLINK_SCHEMA = createSchema({
507
+ code: "olink",
502
508
  kind: "element",
503
509
  tag: OLINK_TAG,
504
510
  requiredAttributes: [...ID_ATTRS],
@@ -508,6 +514,7 @@ var OLINK_SCHEMA = createSchema({
508
514
 
509
515
  // src/schema/elementSchemas/elements/authors/personname.ts
510
516
  var PERSONNAME_SCHEMA = createSchema({
517
+ code: "personname",
511
518
  kind: "group",
512
519
  tag: PERSONNAME_TAG,
513
520
  requiredAttributes: [...ID_ATTRS],
@@ -521,6 +528,7 @@ var PERSONNAME_SCHEMA = createSchema({
521
528
 
522
529
  // src/schema/elementSchemas/elements/authors/firstname.ts
523
530
  var FIRSTNAME_SCHEMA = createSchema({
531
+ code: "firstname",
524
532
  kind: "element",
525
533
  tag: FIRSTNAME_TAG,
526
534
  requiredAttributes: [...ID_ATTRS],
@@ -530,6 +538,7 @@ var FIRSTNAME_SCHEMA = createSchema({
530
538
 
531
539
  // src/schema/elementSchemas/elements/authors/surname.ts
532
540
  var SURNAME_SCHEMA = createSchema({
541
+ code: "surname",
533
542
  kind: "element",
534
543
  tag: SURNAME_TAG,
535
544
  requiredAttributes: [...ID_ATTRS],
@@ -539,6 +548,7 @@ var SURNAME_SCHEMA = createSchema({
539
548
 
540
549
  // src/schema/elementSchemas/elements/authors/honorific.ts
541
550
  var HONORIFIC_SCHEMA = createSchema({
551
+ code: "honorific",
542
552
  kind: "element",
543
553
  tag: HONORIFIC_TAG,
544
554
  requiredAttributes: [...ID_ATTRS],
@@ -548,6 +558,7 @@ var HONORIFIC_SCHEMA = createSchema({
548
558
 
549
559
  // src/schema/elementSchemas/elements/authors/orgname.ts
550
560
  var ORGNAME_SCHEMA = createSchema({
561
+ code: "orgname",
551
562
  kind: "element",
552
563
  tag: ORGNAME_TAG,
553
564
  requiredAttributes: [...ID_ATTRS],
@@ -557,6 +568,7 @@ var ORGNAME_SCHEMA = createSchema({
557
568
 
558
569
  // src/schema/elementSchemas/elements/authors/email.ts
559
570
  var EMAIL_SCHEMA = createSchema({
571
+ code: "email",
560
572
  kind: "element",
561
573
  tag: EMAIL_TAG,
562
574
  requiredAttributes: [...ID_ATTRS],
@@ -566,6 +578,7 @@ var EMAIL_SCHEMA = createSchema({
566
578
 
567
579
  // src/schema/elementSchemas/elements/authors/org.ts
568
580
  var ORG_SCHEMA = createSchema({
581
+ code: "org",
569
582
  kind: "element",
570
583
  tag: ORG_TAG,
571
584
  requiredAttributes: [...ID_ATTRS],
@@ -575,6 +588,7 @@ var ORG_SCHEMA = createSchema({
575
588
 
576
589
  // src/schema/elementSchemas/elements/authors/affiliation.ts
577
590
  var AFFILIATION_SCHEMA = createSchema({
591
+ code: "affiliation",
578
592
  kind: "group",
579
593
  tag: AFFILIATION_TAG,
580
594
  requiredAttributes: [...ID_ATTRS],
@@ -584,6 +598,7 @@ var AFFILIATION_SCHEMA = createSchema({
584
598
 
585
599
  // src/schema/elementSchemas/elements/degrees.ts
586
600
  var DEGREES_SCHEMA = createSchema({
601
+ code: "degrees",
587
602
  kind: "element",
588
603
  tag: DEGREES_TAG,
589
604
  requiredAttributes: [...ID_ATTRS],
@@ -593,6 +608,7 @@ var DEGREES_SCHEMA = createSchema({
593
608
 
594
609
  // src/schema/elementSchemas/elements/dialogue/line.ts
595
610
  var LINE_SCHEMA = createSchema({
611
+ code: "line",
596
612
  kind: "element",
597
613
  tag: LINE_TAG,
598
614
  requiredAttributes: [...ID_ATTRS],
@@ -608,6 +624,7 @@ var LINE_SCHEMA = createSchema({
608
624
 
609
625
  // src/schema/elementSchemas/elements/dialogue/speaker.ts
610
626
  var SPEAKER_SCHEMA = createSchema({
627
+ code: "speaker",
611
628
  kind: "element",
612
629
  tag: SPEAKER_TAG,
613
630
  requiredAttributes: [...ID_ATTRS],
@@ -623,6 +640,7 @@ var SPEAKER_SCHEMA = createSchema({
623
640
 
624
641
  // src/schema/elementSchemas/elements/dialogue/dialogue.ts
625
642
  var DIALOGUE_SCHEMA = createSchema({
643
+ code: "dialogue",
626
644
  kind: "group",
627
645
  tag: DIALOGUE_TAG,
628
646
  requiredAttributes: [...ID_ATTRS],
@@ -642,6 +660,7 @@ var DIALOGUE_SCHEMA = createSchema({
642
660
 
643
661
  // src/schema/elementSchemas/elements/equation.ts
644
662
  var EQUATION_SCHEMA = createSchema({
663
+ code: "equation",
645
664
  kind: "element",
646
665
  tag: EQUATION_TAG,
647
666
  requiredAttributes: [],
@@ -651,6 +670,7 @@ var EQUATION_SCHEMA = createSchema({
651
670
 
652
671
  // src/schema/elementSchemas/elements/figure/img.ts
653
672
  var IMG_SCHEMA = createSchema({
673
+ code: "img",
654
674
  kind: "element",
655
675
  tag: IMG_TAG,
656
676
  requiredAttributes: [...ID_ATTRS, "src", "format"],
@@ -671,6 +691,7 @@ var IMG_SCHEMA = createSchema({
671
691
 
672
692
  // src/schema/elementSchemas/elements/figure/alttext.ts
673
693
  var ALTTEXT_SCHEMA = createSchema({
694
+ code: "alttext",
674
695
  kind: "group",
675
696
  tag: ALTTEXT_TAG,
676
697
  requiredAttributes: [],
@@ -680,6 +701,7 @@ var ALTTEXT_SCHEMA = createSchema({
680
701
 
681
702
  // src/schema/elementSchemas/elements/figure/imageobject.ts
682
703
  var IMAGEOBJECT_SCHEMA = createSchema({
704
+ code: "imageobject",
683
705
  kind: "group",
684
706
  tag: IMAGEOBJECT_TAG,
685
707
  requiredAttributes: [...ID_ATTRS],
@@ -692,6 +714,7 @@ var IMAGEOBJECT_SCHEMA = createSchema({
692
714
 
693
715
  // src/schema/elementSchemas/elements/figure/mediaobject.ts
694
716
  var MEDIAOBJECT_SCHEMA = createSchema({
717
+ code: "mediaobject",
695
718
  kind: "group",
696
719
  tag: MEDIAOBJECT_TAG,
697
720
  requiredAttributes: [...ID_ATTRS],
@@ -701,6 +724,7 @@ var MEDIAOBJECT_SCHEMA = createSchema({
701
724
 
702
725
  // src/schema/elementSchemas/elements/figure/caption1.ts
703
726
  var CAPTION_SCHEMA = createSchema({
727
+ code: "caption1",
704
728
  kind: "group",
705
729
  tag: CAPTION_TAG,
706
730
  requiredAttributes: [...ID_ATTRS],
@@ -710,24 +734,33 @@ var CAPTION_SCHEMA = createSchema({
710
734
 
711
735
  // src/schema/elementSchemas/elements/figure/figsource.ts
712
736
  var FIGSOURCE_SCHEMA = createSchema({
737
+ code: "figsource",
713
738
  kind: "element",
714
739
  tag: FIGSOURCE_TAG,
715
740
  requiredAttributes: [...ID_ATTRS],
716
741
  optionalAttributes: [],
717
- allowedChildTagNames: [...ATOM_TAGS_ALLOWED_CHILDREN]
742
+ allowedChildTagNames: [
743
+ ...ATOM_TAGS_ALLOWED_CHILDREN,
744
+ ...INLINE_ELEMENT_TAGS_ALLOWED_CHILDREN
745
+ ]
718
746
  });
719
747
 
720
748
  // src/schema/elementSchemas/elements/figure/fignote.ts
721
749
  var FIGNOTE_SCHEMA = createSchema({
750
+ code: "fignote",
722
751
  kind: "element",
723
752
  tag: FIGNOTE_TAG,
724
753
  requiredAttributes: [...ID_ATTRS],
725
754
  optionalAttributes: [],
726
- allowedChildTagNames: [...ATOM_TAGS_ALLOWED_CHILDREN]
755
+ allowedChildTagNames: [
756
+ ...ATOM_TAGS_ALLOWED_CHILDREN,
757
+ ...INLINE_ELEMENT_TAGS_ALLOWED_CHILDREN
758
+ ]
727
759
  });
728
760
 
729
761
  // src/schema/elementSchemas/elements/figure/figure.ts
730
762
  var FIGURE_SCHEMA = createSchema({
763
+ code: "figure1",
731
764
  kind: "group",
732
765
  tag: FIGURE_TAG,
733
766
  requiredAttributes: [...ID_ATTRS, "xmlid"],
@@ -748,6 +781,7 @@ var FIGURE_SCHEMA = createSchema({
748
781
 
749
782
  // src/schema/elementSchemas/elements/footnote.ts
750
783
  var FOOTNOTE_SCHEMA = createSchema({
784
+ code: "footnote",
751
785
  kind: "element",
752
786
  tag: FOOTNOTE_TAG,
753
787
  requiredAttributes: [
@@ -769,6 +803,7 @@ var FOOTNOTE_SCHEMA = createSchema({
769
803
 
770
804
  // src/schema/elementSchemas/elements/footnoteNumber.ts
771
805
  var FOOTNOTE_NUMBER_SCHEMA = createSchema({
806
+ code: "footnoteno",
772
807
  kind: "element",
773
808
  tag: FOOTNOTE_NUMBER_TAG,
774
809
  requiredAttributes: [...ID_ATTRS],
@@ -778,6 +813,7 @@ var FOOTNOTE_NUMBER_SCHEMA = createSchema({
778
813
 
779
814
  // src/schema/elementSchemas/elements/informalfigure.ts
780
815
  var INFORMALFIGURE_SCHEMA = createSchema({
816
+ code: "informalfigure",
781
817
  kind: "element",
782
818
  tag: INFORMALFIGURE_TAG,
783
819
  requiredAttributes: [...ID_ATTRS],
@@ -790,6 +826,7 @@ var INFORMALFIGURE_SCHEMA = createSchema({
790
826
 
791
827
  // src/schema/elementSchemas/elements/keywords/keywordset.ts
792
828
  var KEYWORDSET_SCHEMA = createSchema({
829
+ code: "keywordset",
793
830
  kind: "group",
794
831
  tag: KEYWORDSET_TAG,
795
832
  requiredAttributes: [
@@ -810,6 +847,7 @@ var KEYWORDSET_SCHEMA = createSchema({
810
847
 
811
848
  // src/schema/elementSchemas/elements/keywords/keyword.ts
812
849
  var KEYWORD_SCHEMA = createSchema({
850
+ code: "keyword",
813
851
  kind: "element",
814
852
  tag: KEYWORD_TAG,
815
853
  requiredAttributes: [...ID_ATTRS],
@@ -819,6 +857,7 @@ var KEYWORD_SCHEMA = createSchema({
819
857
 
820
858
  // src/schema/elementSchemas/elements/keywords/punc.ts
821
859
  var PUNC_SCHEMA = createSchema({
860
+ code: "punc",
822
861
  kind: "element",
823
862
  tag: PUNC_TAG,
824
863
  requiredAttributes: [...ID_ATTRS],
@@ -826,8 +865,66 @@ var PUNC_SCHEMA = createSchema({
826
865
  allowedChildTagNames: [...ATOM_TAGS_ALLOWED_CHILDREN]
827
866
  });
828
867
 
868
+ // src/schema/elementSchemas/inlineElements/footnoteLink.ts
869
+ var FOOTNOTE_LINK_SCHEMA = createSchema({
870
+ code: "footnote1",
871
+ kind: "inline",
872
+ tag: FOOTNOTE_LINK_TAG,
873
+ requiredAttributes: [...ID_ATTRS],
874
+ optionalAttributes: ["linkend"],
875
+ allowedChildTagNames: [{ tagName: SUP_TAG, required: true }]
876
+ });
877
+
878
+ // src/schema/elementSchemas/inlineElements/inlineequation.ts
879
+ var INLINEEQUATION_SCHEMA = createSchema({
880
+ code: "inlineequation",
881
+ kind: "inline",
882
+ tag: INLINEEQUATION_TAG,
883
+ requiredAttributes: [...ID_ATTRS],
884
+ optionalAttributes: ["linkend"],
885
+ allowedChildTagNames: []
886
+ });
887
+
888
+ // src/schema/elementSchemas/inlineElements/link.ts
889
+ var LINK_SCHEMA = createSchema({
890
+ code: "link",
891
+ kind: "inline",
892
+ tag: LINK_TAG,
893
+ requiredAttributes: [
894
+ ...ID_ATTRS,
895
+ "linkend",
896
+ "data-target-id",
897
+ {
898
+ name: "role",
899
+ values: ["table", "figure", "equation", "footnote", "bibr"],
900
+ defaultValue: ""
901
+ }
902
+ ],
903
+ optionalAttributes: [],
904
+ allowedChildTagNames: [...ATOM_TAGS_ALLOWED_CHILDREN]
905
+ });
906
+
907
+ // src/schema/elementSchemas/inlineElements/uri.ts
908
+ var URI_SCHEMA = createSchema({
909
+ code: "uri",
910
+ kind: "inline",
911
+ tag: URI_TAG,
912
+ requiredAttributes: [...ID_ATTRS],
913
+ optionalAttributes: ["linkend"],
914
+ allowedChildTagNames: [...ATOM_TAGS_ALLOWED_CHILDREN]
915
+ });
916
+
917
+ // src/schema/elementSchemas/inlineElements/index.ts
918
+ var INLINE_ELEMENT_SCHEMAS = [
919
+ URI_SCHEMA,
920
+ FOOTNOTE_LINK_SCHEMA,
921
+ LINK_SCHEMA,
922
+ INLINEEQUATION_SCHEMA
923
+ ];
924
+
829
925
  // src/schema/elementSchemas/elements/label.ts
830
926
  var LABEL_SCHEMA = createSchema({
927
+ code: "label1",
831
928
  kind: "element",
832
929
  tag: LABEL_TAG,
833
930
  requiredAttributes: [...ID_ATTRS],
@@ -839,11 +936,18 @@ var LABEL_SCHEMA = createSchema({
839
936
  defaultValue: "false"
840
937
  }
841
938
  ],
842
- allowedChildTagNames: [...ATOM_TAGS_ALLOWED_CHILDREN]
939
+ allowedChildTagNames: [
940
+ ...ATOM_TAGS_ALLOWED_CHILDREN,
941
+ {
942
+ tagName: LINK_TAG,
943
+ required: false
944
+ }
945
+ ]
843
946
  });
844
947
 
845
948
  // src/schema/elementSchemas/elements/list/token.ts
846
949
  var TOKEN_SCHEMA = createSchema({
950
+ code: "token",
847
951
  kind: "element",
848
952
  tag: TOKEN_TAG,
849
953
  requiredAttributes: [...ID_ATTRS],
@@ -853,6 +957,7 @@ var TOKEN_SCHEMA = createSchema({
853
957
 
854
958
  // src/schema/elementSchemas/elements/list/li.ts
855
959
  var LI_SCHEMA = createSchema({
960
+ code: "li",
856
961
  kind: "element",
857
962
  tag: LI_TAG,
858
963
  requiredAttributes: [...ID_ATTRS],
@@ -881,6 +986,7 @@ var LI_SCHEMA = createSchema({
881
986
 
882
987
  // src/schema/elementSchemas/elements/list/ol.ts
883
988
  var OL_SCHEMA = createSchema({
989
+ code: "ol",
884
990
  kind: "group",
885
991
  tag: OL_TAG,
886
992
  requiredAttributes: [...ID_ATTRS],
@@ -917,6 +1023,7 @@ var OL_SCHEMA = createSchema({
917
1023
 
918
1024
  // src/schema/elementSchemas/elements/list/ul.ts
919
1025
  var UL_SCHEMA = createSchema({
1026
+ code: "ul",
920
1027
  kind: "group",
921
1028
  tag: UL_TAG,
922
1029
  requiredAttributes: [...ID_ATTRS],
@@ -957,6 +1064,7 @@ var UL_SCHEMA = createSchema({
957
1064
 
958
1065
  // src/schema/elementSchemas/elements/para.ts
959
1066
  var PARA_SCHEMA = createSchema({
1067
+ code: "para",
960
1068
  kind: "element",
961
1069
  tag: PARA_TAG,
962
1070
  requiredAttributes: [...ID_ATTRS],
@@ -982,6 +1090,7 @@ var PARA_SCHEMA = createSchema({
982
1090
 
983
1091
  // src/schema/elementSchemas/elements/paragraphNumberTag.ts
984
1092
  var TAG_SCHEMA = createSchema({
1093
+ code: "tag",
985
1094
  kind: "element",
986
1095
  tag: TAG_TAG,
987
1096
  requiredAttributes: [...ID_ATTRS, "data-id"],
@@ -991,6 +1100,7 @@ var TAG_SCHEMA = createSchema({
991
1100
 
992
1101
  // src/schema/elementSchemas/elements/runningHeads/lrh.ts
993
1102
  var LRH_SCHEMA = createSchema({
1103
+ code: "lrh",
994
1104
  kind: "element",
995
1105
  tag: LRH_TAG,
996
1106
  requiredAttributes: [...ID_ATTRS],
@@ -1000,6 +1110,7 @@ var LRH_SCHEMA = createSchema({
1000
1110
 
1001
1111
  // src/schema/elementSchemas/elements/runningHeads/rrh.ts
1002
1112
  var RRH_SCHEMA = createSchema({
1113
+ code: "rrh",
1003
1114
  kind: "element",
1004
1115
  tag: RRH_TAG,
1005
1116
  requiredAttributes: [...ID_ATTRS],
@@ -1009,6 +1120,7 @@ var RRH_SCHEMA = createSchema({
1009
1120
 
1010
1121
  // src/schema/elementSchemas/elements/source.ts
1011
1122
  var SOURCE_SCHEMA = createSchema({
1123
+ code: "source1",
1012
1124
  kind: "element",
1013
1125
  tag: SOURCE_TAG,
1014
1126
  requiredAttributes: [...ID_ATTRS],
@@ -1025,6 +1137,7 @@ var SOURCE_SCHEMA = createSchema({
1025
1137
 
1026
1138
  // src/schema/elementSchemas/elements/subtitle.ts
1027
1139
  var SUBTITLE_SCHEMA = createSchema({
1140
+ code: "subtitle1",
1028
1141
  kind: "element",
1029
1142
  tag: SUBTITLE_TAG,
1030
1143
  requiredAttributes: [...ID_ATTRS],
@@ -1040,15 +1153,20 @@ var SUBTITLE_SCHEMA = createSchema({
1040
1153
 
1041
1154
  // src/schema/elementSchemas/elements/table/tp.ts
1042
1155
  var TP_SCHEMA = createSchema({
1156
+ code: "tp",
1043
1157
  kind: "element",
1044
1158
  tag: TP_TAG,
1045
1159
  requiredAttributes: [],
1046
- optionalAttributes: [ID_ATTRS[0], ID_ATTRS[1]],
1047
- allowedChildTagNames: []
1160
+ optionalAttributes: [...ID_ATTRS],
1161
+ allowedChildTagNames: [
1162
+ ...ATOM_TAGS_ALLOWED_CHILDREN,
1163
+ ...INLINE_ELEMENT_TAGS_ALLOWED_CHILDREN
1164
+ ]
1048
1165
  });
1049
1166
 
1050
1167
  // src/schema/elementSchemas/elements/table/td.ts
1051
1168
  var TD_SCHEMA = createSchema({
1169
+ code: "td",
1052
1170
  kind: "group",
1053
1171
  tag: TD_TAG,
1054
1172
  requiredAttributes: [...ID_ATTRS],
@@ -1062,37 +1180,41 @@ var TD_SCHEMA = createSchema({
1062
1180
 
1063
1181
  // src/schema/elementSchemas/elements/table/tr.ts
1064
1182
  var TR_SCHEMA = createSchema({
1183
+ code: "tr",
1065
1184
  kind: "group",
1066
1185
  tag: TR_TAG,
1067
1186
  requiredAttributes: [],
1068
- optionalAttributes: [...LAYOUT_ATTRIBUTES, ID_ATTRS[0], ID_ATTRS[1], "width"],
1187
+ optionalAttributes: [...LAYOUT_ATTRIBUTES, ...ID_ATTRS, "width"],
1069
1188
  allowedChildTagNames: [{ tagName: TD_TAG, required: true }]
1070
1189
  });
1071
1190
 
1072
1191
  // src/schema/elementSchemas/elements/table/thead.ts
1073
1192
  var THEAD_SCHEMA = createSchema({
1193
+ code: "thead",
1074
1194
  kind: "element",
1075
1195
  tag: THEAD_TAG,
1076
1196
  requiredAttributes: [],
1077
- optionalAttributes: [ID_ATTRS[0], ID_ATTRS[1]],
1197
+ optionalAttributes: [...ID_ATTRS],
1078
1198
  allowedChildTagNames: [{ tagName: TR_TAG, required: true }]
1079
1199
  });
1080
1200
 
1081
1201
  // src/schema/elementSchemas/elements/table/tbody.ts
1082
1202
  var TBODY_SCHEMA = createSchema({
1203
+ code: "tbody",
1083
1204
  kind: "group",
1084
1205
  tag: TBODY_TAG,
1085
1206
  requiredAttributes: [],
1086
- optionalAttributes: [ID_ATTRS[0], ID_ATTRS[1]],
1207
+ optionalAttributes: [...ID_ATTRS],
1087
1208
  allowedChildTagNames: [{ tagName: TR_TAG, required: true }]
1088
1209
  });
1089
1210
 
1090
1211
  // src/schema/elementSchemas/elements/table/htmlTable.ts
1091
1212
  var HTML_TABLE_SCHEMA = createSchema({
1213
+ code: "table",
1092
1214
  kind: "group",
1093
1215
  tag: HTML_TABLE_TAG,
1094
1216
  requiredAttributes: [],
1095
- optionalAttributes: [ID_ATTRS[0], ID_ATTRS[1]],
1217
+ optionalAttributes: [...ID_ATTRS],
1096
1218
  allowedChildTagNames: [
1097
1219
  { tagName: THEAD_TAG, required: false },
1098
1220
  { tagName: TBODY_TAG, required: true }
@@ -1101,6 +1223,7 @@ var HTML_TABLE_SCHEMA = createSchema({
1101
1223
 
1102
1224
  // src/schema/elementSchemas/elements/table/tgroup.ts
1103
1225
  var TGROUP_SCHEMA = createSchema({
1226
+ code: "tgroup",
1104
1227
  kind: "group",
1105
1228
  tag: TGROUP_TAG,
1106
1229
  requiredAttributes: [...ID_ATTRS, "cols"],
@@ -1110,24 +1233,30 @@ var TGROUP_SCHEMA = createSchema({
1110
1233
 
1111
1234
  // src/schema/elementSchemas/elements/table/tblfn.ts
1112
1235
  var TBLFN_SCHEMA = createSchema({
1236
+ code: "tblfn",
1113
1237
  kind: "element",
1114
1238
  tag: TBLFN_TAG,
1115
1239
  requiredAttributes: [...ID_ATTRS],
1116
1240
  optionalAttributes: [],
1117
- allowedChildTagNames: []
1241
+ allowedChildTagNames: [
1242
+ ...ATOM_TAGS_ALLOWED_CHILDREN,
1243
+ ...INLINE_ELEMENT_TAGS_ALLOWED_CHILDREN
1244
+ ]
1118
1245
  });
1119
1246
 
1120
1247
  // src/schema/elementSchemas/elements/table/tblsource.ts
1121
1248
  var TBLSOURCE_SCHEMA = createSchema({
1249
+ code: "tblsource",
1122
1250
  kind: "element",
1123
1251
  tag: TBLSOURCE_TAG,
1124
1252
  requiredAttributes: [],
1125
1253
  optionalAttributes: [],
1126
- allowedChildTagNames: []
1254
+ allowedChildTagNames: [...ATOM_TAGS_ALLOWED_CHILDREN]
1127
1255
  });
1128
1256
 
1129
1257
  // src/schema/elementSchemas/elements/table/table1.ts
1130
1258
  var TABLE_SCHEMA = createSchema({
1259
+ code: "table1",
1131
1260
  kind: "group",
1132
1261
  tag: TABLE_TAG,
1133
1262
  requiredAttributes: [...ID_ATTRS, "xmlid", "role"],
@@ -1150,6 +1279,7 @@ var TABLE_SCHEMA = createSchema({
1150
1279
 
1151
1280
  // src/schema/elementSchemas/elements/title.ts
1152
1281
  var TITLE_SCHEMA = createSchema({
1282
+ code: "title1",
1153
1283
  kind: "element",
1154
1284
  tag: TITLE_TAG,
1155
1285
  requiredAttributes: [...ID_ATTRS],
@@ -1225,6 +1355,7 @@ var ELEMENT_SCHEMAS = [
1225
1355
 
1226
1356
  // src/schema/elementSchemas/groupElements/abstract.ts
1227
1357
  var ABSTRACT_SCHEMA = createSchema({
1358
+ code: "abstract1",
1228
1359
  kind: "group",
1229
1360
  tag: ABSTRACT_TAG,
1230
1361
  requiredAttributes: [
@@ -1253,6 +1384,7 @@ var ABSTRACT_SCHEMA = createSchema({
1253
1384
 
1254
1385
  // src/schema/elementSchemas/groupElements/appendix.ts
1255
1386
  var APPENDIX_SCHEMA = createSchema({
1387
+ code: "appendix",
1256
1388
  kind: "group",
1257
1389
  tag: APPENDIX_TAG,
1258
1390
  requiredAttributes: [...ID_ATTRS, "id", "xmlid"],
@@ -1266,6 +1398,7 @@ var APPENDIX_SCHEMA = createSchema({
1266
1398
 
1267
1399
  // src/schema/elementSchemas/groupElements/blockquote.ts
1268
1400
  var BLOCKQUOTE_SCHEMA = createSchema({
1401
+ code: "blockquote",
1269
1402
  kind: "group",
1270
1403
  tag: BLOCKQUOTE_TAG,
1271
1404
  requiredAttributes: [...ID_ATTRS],
@@ -1291,6 +1424,7 @@ var BLOCKQUOTE_SCHEMA = createSchema({
1291
1424
 
1292
1425
  // src/schema/elementSchemas/groupElements/box.ts
1293
1426
  var BOX_SCHEMA = createSchema({
1427
+ code: "sidebar",
1294
1428
  kind: "group",
1295
1429
  tag: SIDEBAR_TAG,
1296
1430
  requiredAttributes: [
@@ -1318,6 +1452,7 @@ var BOX_SCHEMA = createSchema({
1318
1452
 
1319
1453
  // src/schema/elementSchemas/groupElements/chapter.ts
1320
1454
  var CHAPTER_SCHEMA = createSchema({
1455
+ code: "chapter",
1321
1456
  kind: "group",
1322
1457
  tag: CHAPTER_TAG,
1323
1458
  requiredAttributes: [...ID_ATTRS, "xmlid"],
@@ -1351,6 +1486,7 @@ var CHAPTER_SCHEMA = createSchema({
1351
1486
 
1352
1487
  // src/schema/elementSchemas/groupElements/epigraph.ts
1353
1488
  var EPIGRAPH_SCHEMA = createSchema({
1489
+ code: "epigraph",
1354
1490
  kind: "group",
1355
1491
  tag: EPIGRAPH_TAG,
1356
1492
  requiredAttributes: [...ID_ATTRS],
@@ -1368,9 +1504,9 @@ var EPIGRAPH_SCHEMA = createSchema({
1368
1504
 
1369
1505
  // src/schema/elementSchemas/groupElements/footnoteSection.ts
1370
1506
  var FOOTNOTE_SECTION_SCHEMA = createSchema({
1507
+ code: "footnoteSection",
1371
1508
  kind: "group",
1372
1509
  tag: SECTION_TAG,
1373
- role: "FOOTNOTE" /* FOOTNOTE */,
1374
1510
  requiredAttributes: [
1375
1511
  ...ID_ATTRS,
1376
1512
  {
@@ -1388,9 +1524,9 @@ var FOOTNOTE_SECTION_SCHEMA = createSchema({
1388
1524
 
1389
1525
  // src/schema/elementSchemas/groupElements/heading.ts
1390
1526
  var HEADING_SCHEMA = createSchema({
1527
+ code: "heading",
1391
1528
  kind: "group",
1392
1529
  tag: SECTION_TAG,
1393
- role: "HEADING" /* HEADING */,
1394
1530
  requiredAttributes: [
1395
1531
  ...ID_ATTRS,
1396
1532
  "xmlid",
@@ -1423,6 +1559,7 @@ var HEADING_SCHEMA = createSchema({
1423
1559
 
1424
1560
  // src/schema/elementSchemas/groupElements/info.ts
1425
1561
  var INFO_SCHEMA = createSchema({
1562
+ code: "info1",
1426
1563
  kind: "group",
1427
1564
  tag: INFO_TAG,
1428
1565
  requiredAttributes: [...ID_ATTRS],
@@ -1439,6 +1576,7 @@ var INFO_SCHEMA = createSchema({
1439
1576
 
1440
1577
  // src/schema/elementSchemas/groupElements/poem.ts
1441
1578
  var POEM_SCHEMA = createSchema({
1579
+ code: "poem",
1442
1580
  kind: "group",
1443
1581
  tag: POEM_TAG,
1444
1582
  requiredAttributes: [...ID_ATTRS],
@@ -1467,59 +1605,6 @@ var GROUP_ELEMENT_SCHEMAS = [
1467
1605
  AFFILIATION_SCHEMA
1468
1606
  ];
1469
1607
 
1470
- // src/schema/elementSchemas/inlineElements/footnoteLink.ts
1471
- var FOOTNOTE_LINK_SCHEMA = createSchema({
1472
- kind: "inline",
1473
- tag: FOOTNOTE_LINK_TAG,
1474
- requiredAttributes: [...ID_ATTRS],
1475
- optionalAttributes: ["linkend"],
1476
- allowedChildTagNames: [{ tagName: SUP_TAG, required: true }]
1477
- });
1478
-
1479
- // src/schema/elementSchemas/inlineElements/inlineequation.ts
1480
- var INLINEEQUATION_SCHEMA = createSchema({
1481
- kind: "inline",
1482
- tag: INLINEEQUATION_TAG,
1483
- requiredAttributes: [...ID_ATTRS],
1484
- optionalAttributes: ["linkend"],
1485
- allowedChildTagNames: []
1486
- });
1487
-
1488
- // src/schema/elementSchemas/inlineElements/link.ts
1489
- var LINK_SCHEMA = createSchema({
1490
- kind: "inline",
1491
- tag: LINK_TAG,
1492
- requiredAttributes: [
1493
- ...ID_ATTRS,
1494
- "linkend",
1495
- "data-target-id",
1496
- {
1497
- name: "role",
1498
- values: ["table", "figure", "equation", "footnote"],
1499
- defaultValue: ""
1500
- }
1501
- ],
1502
- optionalAttributes: [],
1503
- allowedChildTagNames: [...ATOM_TAGS_ALLOWED_CHILDREN]
1504
- });
1505
-
1506
- // src/schema/elementSchemas/inlineElements/uri.ts
1507
- var URI_SCHEMA = createSchema({
1508
- kind: "inline",
1509
- tag: URI_TAG,
1510
- requiredAttributes: [...ID_ATTRS],
1511
- optionalAttributes: ["linkend"],
1512
- allowedChildTagNames: [...ATOM_TAGS_ALLOWED_CHILDREN]
1513
- });
1514
-
1515
- // src/schema/elementSchemas/inlineElements/index.ts
1516
- var INLINE_ELEMENT_SCHEMAS = [
1517
- URI_SCHEMA,
1518
- FOOTNOTE_LINK_SCHEMA,
1519
- LINK_SCHEMA,
1520
- INLINEEQUATION_SCHEMA
1521
- ];
1522
-
1523
1608
  // src/schema/schemas.ts
1524
1609
  var SCHEMAS = [
1525
1610
  ...ATOM_SCHEMAS,
@@ -1528,10 +1613,7 @@ var SCHEMAS = [
1528
1613
  ...INLINE_ELEMENT_SCHEMAS
1529
1614
  ];
1530
1615
  var SCHEMA_MAP = new Map(
1531
- SCHEMAS.map((schema) => [
1532
- schema.tag.toUpperCase() + (schema.role?.toUpperCase() ?? ""),
1533
- schema
1534
- ])
1616
+ SCHEMAS.map((schema) => [schema.code, schema])
1535
1617
  );
1536
1618
 
1537
1619
  // src/schema/shared/ignoredElements.ts
@@ -1566,41 +1648,36 @@ var isIgnoredAttribute = (attribute) => IGNORED_ATTRIBUTES.includes(attribute) |
1566
1648
  (startsWith) => attribute.startsWith(startsWith)
1567
1649
  );
1568
1650
  var isIgnoredElement = (element) => IGNORED_ELEMENT_SELECTORS.some((selector) => element.matches(selector));
1569
- var findSchemaByTag = (tagName, role) => {
1570
- if (role) {
1571
- return SCHEMA_MAP.get(tagName.toUpperCase() + role);
1572
- }
1573
- return SCHEMA_MAP.get(tagName.toUpperCase());
1574
- };
1651
+ var findSchemaByCode = (code) => SCHEMA_MAP.get(code);
1575
1652
  var findSchemaByElement = (element) => {
1576
1653
  const isInsertion = element.classList.contains("ins");
1577
1654
  const isDeletion = element.classList.contains("del");
1578
1655
  const isQueryComment = element.classList.contains("cmtQurySection");
1579
1656
  const role = element.getAttribute("role");
1657
+ if (isQueryComment) {
1658
+ return findSchemaByCode("commentQuerySection");
1659
+ }
1660
+ if (isInsertion) {
1661
+ return findSchemaByCode("insertion");
1662
+ }
1663
+ if (isDeletion) {
1664
+ return findSchemaByCode("deletion");
1665
+ }
1580
1666
  if (role) {
1581
1667
  if (role.startsWith("H")) {
1582
- return SCHEMA_MAP.get(
1583
- element.tagName.toUpperCase() + "HEADING" /* HEADING */
1584
- );
1668
+ return findSchemaByCode("heading");
1585
1669
  }
1586
1670
  if (role === "ch" || role === "bk") {
1587
- return SCHEMA_MAP.get(
1588
- element.tagName.toUpperCase() + "FOOTNOTE" /* FOOTNOTE */
1589
- );
1671
+ return findSchemaByCode("footnoteSection");
1590
1672
  }
1591
1673
  }
1592
- if (isInsertion) {
1593
- return SCHEMA_MAP.get(element.tagName.toUpperCase() + "INS" /* INS */);
1674
+ const candidates = [...SCHEMA_MAP.values()].filter(
1675
+ (schema) => schema.tag === element.tagName.toUpperCase()
1676
+ );
1677
+ if (candidates.length > 0) {
1678
+ return candidates[0];
1594
1679
  }
1595
- if (isDeletion) {
1596
- return SCHEMA_MAP.get(element.tagName.toUpperCase() + "DEL" /* DEL */);
1597
- }
1598
- if (isQueryComment) {
1599
- return SCHEMA_MAP.get(
1600
- element.tagName.toUpperCase() + "QUERYCOMMENTSWRAPPER" /* QUERYCOMMENTSWRAPPER */
1601
- );
1602
- }
1603
- return SCHEMA_MAP.get(element.tagName.toUpperCase());
1680
+ return void 0;
1604
1681
  };
1605
1682
  var isAttributeRestricted = (attr) => typeof attr !== "string";
1606
1683
  var getAttributeName = (attribute) => typeof attribute === "string" ? attribute : attribute.name;
@@ -1627,6 +1704,420 @@ var createElement = ({
1627
1704
  }
1628
1705
  return element;
1629
1706
  };
1707
+
1708
+ // src/validation/utils/retrieveTextIgnoringNodesWithSelector.ts
1709
+ var retrieveTextIgnoringNodesWithSelector = (element, selector = ".del") => {
1710
+ const clonedElement = element.cloneNode(true);
1711
+ for (const delElement of clonedElement.querySelectorAll(selector)) {
1712
+ delElement.remove();
1713
+ }
1714
+ return clonedElement.textContent || "";
1715
+ };
1716
+
1717
+ // src/validation/validateFootnotes.ts
1718
+ var extractFootnoteNumber = (footnote) => {
1719
+ if (!footnote) return "no label";
1720
+ const footnoteNumberText = retrieveTextIgnoringNodesWithSelector(footnote);
1721
+ const footnoteNumber = Number(footnoteNumberText);
1722
+ if (!Number.isInteger(footnoteNumber) || footnoteNumber <= 0) {
1723
+ return "no label";
1724
+ }
1725
+ return footnoteNumber;
1726
+ };
1727
+ var validateFootnoteCue = (footnoteElement, root) => {
1728
+ const errors = [];
1729
+ const store = footnoteElement.getAttribute("store");
1730
+ if (!store) {
1731
+ return errors;
1732
+ }
1733
+ const linkend = footnoteElement.getAttribute("xmlid") || "";
1734
+ const footnoteNumber = footnoteElement.querySelector(
1735
+ FOOTNOTE_NUMBER_SCHEMA.tag
1736
+ );
1737
+ const footnoteLink = root.querySelector(
1738
+ `${FOOTNOTE_LINK_SCHEMA.tag}[linkend='${CSS.escape(linkend)}']`
1739
+ );
1740
+ if (footnoteLink) {
1741
+ return errors;
1742
+ }
1743
+ if (!footnoteNumber) {
1744
+ errors.push({
1745
+ id: `footnote-number-missing-${store}`,
1746
+ store,
1747
+ title: "Footnote number missing",
1748
+ kind: "missing",
1749
+ description: "The footnote number is missing. Please add it to the footnote.",
1750
+ level: "blocker"
1751
+ });
1752
+ }
1753
+ const label = extractFootnoteNumber(footnoteNumber);
1754
+ errors.push({
1755
+ id: `unreferenced-footnote-${store}`,
1756
+ store,
1757
+ title: "Unreferenced footnote",
1758
+ kind: "unlinked",
1759
+ description: `The footnote ${label} is not referenced to any footnote cue in this chapter. Please reference it in the chapter.`,
1760
+ level: "blocker"
1761
+ });
1762
+ return errors;
1763
+ };
1764
+ var validateConsecutiveFootnotes = (root) => {
1765
+ const footnotes = Array.from(root.querySelectorAll(FOOTNOTE_SCHEMA.tag));
1766
+ if (footnotes.length === 0) {
1767
+ return [];
1768
+ }
1769
+ for (const [index, footnote] of footnotes.entries()) {
1770
+ const store = footnote.getAttribute("store") || "";
1771
+ const expectedNumber = index + 1;
1772
+ const footnoteNumberElement = footnote.querySelector(
1773
+ FOOTNOTE_NUMBER_SCHEMA.tag
1774
+ );
1775
+ if (!footnoteNumberElement) {
1776
+ continue;
1777
+ }
1778
+ const label = extractFootnoteNumber(footnoteNumberElement);
1779
+ if (label === expectedNumber) {
1780
+ continue;
1781
+ }
1782
+ return [
1783
+ {
1784
+ id: `non-consecutive-footnote-numbers-${store}`,
1785
+ store,
1786
+ title: "Non-consecutive footnote numbers",
1787
+ kind: "missing",
1788
+ description: "Footnote numbers must be consecutive. Please reorder the footnotes.",
1789
+ level: "warning"
1790
+ }
1791
+ ];
1792
+ }
1793
+ return [];
1794
+ };
1795
+ var validateConsecutiveFootnoteCues = (root) => {
1796
+ const footnoteLinks = Array.from(
1797
+ root.querySelectorAll(FOOTNOTE_LINK_SCHEMA.tag)
1798
+ );
1799
+ if (footnoteLinks.length === 0) {
1800
+ return [];
1801
+ }
1802
+ for (const [index, footnoteLink] of footnoteLinks.entries()) {
1803
+ const store = footnoteLink.getAttribute("store") || "";
1804
+ const expectedNumber = index + 1;
1805
+ const label = extractFootnoteNumber(footnoteLink);
1806
+ if (label === expectedNumber) {
1807
+ continue;
1808
+ }
1809
+ return [
1810
+ {
1811
+ id: `non-consecutive-footnote-cues-${store}`,
1812
+ store,
1813
+ title: "Non-consecutive footnote cues",
1814
+ kind: "missing",
1815
+ description: "Footnote cues must be consecutive. Please reorder the footnote cues.",
1816
+ level: "warning"
1817
+ }
1818
+ ];
1819
+ }
1820
+ return [];
1821
+ };
1822
+ var validateFootnotes = (root) => {
1823
+ const errors = [];
1824
+ for (const footnote of root.querySelectorAll(FOOTNOTE_SCHEMA.tag)) {
1825
+ errors.push(...validateFootnoteCue(footnote, root));
1826
+ }
1827
+ errors.push(...validateConsecutiveFootnotes(root));
1828
+ errors.push(...validateConsecutiveFootnoteCues(root));
1829
+ return errors;
1830
+ };
1831
+
1832
+ // src/validation/validateLinkend.ts
1833
+ var findElementInCurrentChapter = (root, linkend) => {
1834
+ return !!root.querySelector(`[xmlid='${CSS.escape(linkend)}']`);
1835
+ };
1836
+ var findElementInReferenceChapters = (linkend, referenceChapterLinkends) => {
1837
+ return referenceChapterLinkends.includes(linkend);
1838
+ };
1839
+ var validateLinkend = (linkElement, root, referenceChapterLinkends = []) => {
1840
+ const store = linkElement.getAttribute("store");
1841
+ if (!store) {
1842
+ return [];
1843
+ }
1844
+ const linkend = linkElement.getAttribute("linkend");
1845
+ if (!linkend) {
1846
+ return [];
1847
+ }
1848
+ const isLinkFootnoteCue = linkElement.tagName.toUpperCase() === FOOTNOTE_LINK_SCHEMA.tag;
1849
+ if (isLinkFootnoteCue) {
1850
+ if (findElementInCurrentChapter(root, linkend)) {
1851
+ return [];
1852
+ }
1853
+ return [
1854
+ {
1855
+ id: `unlinked-footnote-cue-${store}`,
1856
+ store,
1857
+ title: "Unlinked footnote cue",
1858
+ kind: "unlinked",
1859
+ description: "This footnote cue is not referenced to any footnote in this chapter. Please link it again manually.",
1860
+ level: "blocker"
1861
+ }
1862
+ ];
1863
+ }
1864
+ if (findElementInCurrentChapter(root, linkend) || findElementInReferenceChapters(linkend, referenceChapterLinkends)) {
1865
+ return [];
1866
+ }
1867
+ return [
1868
+ {
1869
+ id: `unlinked-element-${store}`,
1870
+ store,
1871
+ title: "Unlinked element",
1872
+ kind: "unlinked",
1873
+ description: "This link is not referenced to any element in the current chapter or reference chapters. Please link it again manually.",
1874
+ level: "blocker"
1875
+ }
1876
+ ];
1877
+ };
1878
+ var validateLinkends = (root, referenceChapterLinkends = []) => {
1879
+ const errors = [];
1880
+ for (const linkElement of root.querySelectorAll("[linkend]")) {
1881
+ errors.push(
1882
+ ...validateLinkend(linkElement, root, referenceChapterLinkends)
1883
+ );
1884
+ }
1885
+ return errors;
1886
+ };
1887
+
1888
+ // src/validation/validateAttributes.ts
1889
+ var validateAttributes = (element, schema) => {
1890
+ const errors = [];
1891
+ const definitions = [
1892
+ ...schema.requiredAttributes,
1893
+ ...schema.optionalAttributes
1894
+ ];
1895
+ for (const attribute of schema.requiredAttributes) {
1896
+ const name = getAttributeName(attribute);
1897
+ if (!element.hasAttribute(name)) {
1898
+ errors.push({
1899
+ id: `missing-required-attribute-${name}`,
1900
+ store: element.id,
1901
+ title: `Missing required attribute "${name}"`,
1902
+ level: "warning",
1903
+ kind: "missing",
1904
+ description: `The attribute "${name}" is required but not present in the element.`
1905
+ });
1906
+ }
1907
+ }
1908
+ for (const name of element.getAttributeNames()) {
1909
+ if (isIgnoredAttribute(name)) {
1910
+ continue;
1911
+ }
1912
+ const definition = findAttributeDefinitionByName(definitions, name);
1913
+ if (!definition) {
1914
+ errors.push({
1915
+ id: `unexpected-attribute-${name}`,
1916
+ store: element.id,
1917
+ title: `Unexpected attribute "${name}"`,
1918
+ level: "warning",
1919
+ kind: "forbidden",
1920
+ description: `The attribute "${name}" is not allowed in this element.`
1921
+ });
1922
+ continue;
1923
+ }
1924
+ if (!isAttributeRestricted(definition)) {
1925
+ continue;
1926
+ }
1927
+ const value = element.getAttribute(name);
1928
+ if (value === null) {
1929
+ continue;
1930
+ }
1931
+ if (!definition.values.includes(value)) {
1932
+ errors.push({
1933
+ id: `forbidden-attribute-value-${name}-${value}`,
1934
+ store: element.id,
1935
+ title: `Invalid attribute value "${value}"`,
1936
+ level: "warning",
1937
+ kind: "forbidden",
1938
+ description: `The attribute "${name}" has an invalid value "${value}".`
1939
+ });
1940
+ }
1941
+ }
1942
+ return errors;
1943
+ };
1944
+
1945
+ // src/validation/validateChildren.ts
1946
+ var validateElementAgainstSchema = (element, schema) => {
1947
+ const errors = [];
1948
+ if (element.tagName.toUpperCase() !== schema.tag) {
1949
+ errors.push({
1950
+ id: `expected-element-${schema.tag}`,
1951
+ store: element.id,
1952
+ title: `Expected ${schema.tag}, got ${element.tagName}`,
1953
+ level: "warning",
1954
+ kind: "forbidden",
1955
+ description: `The element is not allowed in this context.`
1956
+ });
1957
+ }
1958
+ if (schema.code === "insertion" && !element.classList.contains("ins")) {
1959
+ errors.push({
1960
+ id: `missing-class-ins-${element.id}`,
1961
+ store: element.id,
1962
+ title: 'Missing class "ins" for insertion element',
1963
+ level: "warning",
1964
+ kind: "missing",
1965
+ description: `The element is missing the class "ins".`
1966
+ });
1967
+ }
1968
+ if (schema.code === "deletion" && !element.classList.contains("del")) {
1969
+ errors.push({
1970
+ id: `missing-class-del-${element.id}`,
1971
+ store: element.id,
1972
+ title: 'Missing class "del" for deletion element',
1973
+ level: "warning",
1974
+ kind: "missing",
1975
+ description: `The element is missing the class "del".`
1976
+ });
1977
+ }
1978
+ if (schema.code === "commentQuerySection" && !element.classList.contains("cmtQurySection")) {
1979
+ errors.push({
1980
+ id: `missing-class-cmtQurySection-${element.id}`,
1981
+ store: element.id,
1982
+ title: 'Missing class "cmtQurySection" for comment query section',
1983
+ level: "warning",
1984
+ kind: "missing",
1985
+ description: `The element is missing the class "cmtQurySection".`
1986
+ });
1987
+ }
1988
+ errors.push(...validateAttributes(element, schema));
1989
+ errors.push(...validateChildren(element, schema));
1990
+ return errors;
1991
+ };
1992
+ var validateChildren = (element, schema) => {
1993
+ const errors = [];
1994
+ const childElements = [...element.children].filter(
1995
+ (child) => !isIgnoredElement(child)
1996
+ );
1997
+ const allowedChildren = [...schema.allowedChildTagNames];
1998
+ for (const child of childElements) {
1999
+ const childTag = child.tagName.toUpperCase();
2000
+ const allowedChild = allowedChildren.find(
2001
+ (candidate) => candidate.tagName === childTag
2002
+ );
2003
+ if (!allowedChild) {
2004
+ errors.push({
2005
+ id: `forbidden-child-element-${child.tagName}`,
2006
+ store: child.id,
2007
+ title: `Forbidden child element ${child.tagName}`,
2008
+ level: "warning",
2009
+ kind: "forbidden",
2010
+ description: `The child element ${child.tagName} is not allowed in this context.`
2011
+ });
2012
+ continue;
2013
+ }
2014
+ const childSchema = findSchemaByElement(child);
2015
+ if (!childSchema) {
2016
+ errors.push({
2017
+ id: `no-schema-found-for-child-element-${child.tagName}`,
2018
+ store: child.id,
2019
+ title: `No schema found for child element ${child.tagName}`,
2020
+ level: "warning",
2021
+ kind: "missing",
2022
+ description: `No schema found for child element ${child.tagName}.`
2023
+ });
2024
+ continue;
2025
+ }
2026
+ errors.push(...validateElementAgainstSchema(child, childSchema));
2027
+ }
2028
+ for (const allowedChild of allowedChildren) {
2029
+ if (!allowedChild.required) {
2030
+ continue;
2031
+ }
2032
+ const hasChild = childElements.some(
2033
+ (child) => child.tagName.toUpperCase() === allowedChild.tagName
2034
+ );
2035
+ if (!hasChild) {
2036
+ errors.push({
2037
+ id: `missing-required-child-element-${allowedChild.tagName}`,
2038
+ store: element.id,
2039
+ title: `Missing required child element ${allowedChild.tagName}`,
2040
+ level: "warning",
2041
+ kind: "missing",
2042
+ description: `The child element ${allowedChild.tagName} is required but not present.`
2043
+ });
2044
+ }
2045
+ }
2046
+ if (schema.allowedChildTagNames.size === 0 && childElements.length > 0) {
2047
+ errors.push({
2048
+ id: `leaf-element-cannot-contain-child-elements-${element.id}`,
2049
+ store: element.id,
2050
+ title: "Leaf element cannot contain child elements",
2051
+ level: "warning",
2052
+ kind: "forbidden",
2053
+ description: `The element is a leaf element and cannot contain child elements.`
2054
+ });
2055
+ }
2056
+ return errors;
2057
+ };
2058
+
2059
+ // src/validation/utils/parseXML.ts
2060
+ var parseXml = (xml) => {
2061
+ const doc = new DOMParser().parseFromString(xml.trim(), "application/xml");
2062
+ const parserError = doc.querySelector("parsererror");
2063
+ if (parserError) {
2064
+ throw new Error(
2065
+ `Unable to parse XML: ${parserError.textContent ?? "unknown error"}`
2066
+ );
2067
+ }
2068
+ const element = doc.documentElement;
2069
+ if (!element) {
2070
+ throw new Error("XML string did not produce an element");
2071
+ }
2072
+ return element;
2073
+ };
2074
+
2075
+ // src/validation/validateXml.ts
2076
+ var getLinkableRoles = () => {
2077
+ const linkRoleDefinition = findAttributeDefinitionByName(
2078
+ LINK_SCHEMA.requiredAttributes,
2079
+ "role"
2080
+ );
2081
+ if (!linkRoleDefinition) {
2082
+ return [];
2083
+ }
2084
+ if (isAttributeRestricted(linkRoleDefinition)) {
2085
+ return linkRoleDefinition.values;
2086
+ }
2087
+ return [];
2088
+ };
2089
+ var validateElement = (element, root, referenceChapterLinkends) => {
2090
+ if (isIgnoredElement(element)) {
2091
+ return [];
2092
+ }
2093
+ const errors = [];
2094
+ const schema = findSchemaByElement(element);
2095
+ if (schema) {
2096
+ errors.push(...validateElementAgainstSchema(element, schema));
2097
+ const role = element.getAttribute("role") || "";
2098
+ const linkableRoles = getLinkableRoles();
2099
+ if (schema.tag === LINK_SCHEMA.tag && linkableRoles.includes(role) || schema.tag === FOOTNOTE_LINK_SCHEMA.tag) {
2100
+ errors.push(...validateLinkend(element, root, referenceChapterLinkends));
2101
+ }
2102
+ if (schema.tag === FOOTNOTE_SCHEMA.tag) {
2103
+ errors.push(...validateFootnoteCue(element, root));
2104
+ }
2105
+ }
2106
+ for (const child of Array.from(element.children)) {
2107
+ errors.push(...validateElement(child, root, referenceChapterLinkends));
2108
+ }
2109
+ return errors;
2110
+ };
2111
+ var validateXml = (xml, referenceChapterLinkends) => {
2112
+ const root = parseXml(xml);
2113
+ const errors = [];
2114
+ errors.push(...validateConsecutiveFootnotes(root));
2115
+ errors.push(...validateConsecutiveFootnoteCues(root));
2116
+ for (const child of Array.from(root.children)) {
2117
+ errors.push(...validateElement(child, root, referenceChapterLinkends));
2118
+ }
2119
+ return errors;
2120
+ };
1630
2121
  export {
1631
2122
  ABSTRACT_SCHEMA,
1632
2123
  ABSTRACT_TAG,
@@ -1658,7 +2149,6 @@ export {
1658
2149
  DELETION_SCHEMA,
1659
2150
  DIALOGUE_SCHEMA,
1660
2151
  DIALOGUE_TAG,
1661
- ELEMENT_ROLE,
1662
2152
  ELEMENT_SCHEMAS,
1663
2153
  ELEMENT_TAGS,
1664
2154
  ELE_ID_ATTRIBUTE,
@@ -1813,10 +2303,20 @@ export {
1813
2303
  U_SCHEMA,
1814
2304
  createElement,
1815
2305
  findAttributeDefinitionByName,
2306
+ findSchemaByCode,
1816
2307
  findSchemaByElement,
1817
- findSchemaByTag,
1818
2308
  getAttributeName,
1819
2309
  isAttributeRestricted,
1820
2310
  isIgnoredAttribute,
1821
- isIgnoredElement
2311
+ isIgnoredElement,
2312
+ validateAttributes,
2313
+ validateConsecutiveFootnoteCues,
2314
+ validateConsecutiveFootnotes,
2315
+ validateElement,
2316
+ validateElementAgainstSchema,
2317
+ validateFootnoteCue,
2318
+ validateFootnotes,
2319
+ validateLinkend,
2320
+ validateLinkends,
2321
+ validateXml
1822
2322
  };