magic-editor-x 2.4.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +63 -0
- package/README.md +140 -62
- package/bin/magic-editor-x.mjs +55 -8
- package/dist/admin/{AuditPage-guB0SiGS.mjs → AuditPage-Be78C7EC.mjs} +4 -3
- package/dist/admin/{AuditPage-C2u6z4aN.js → AuditPage-iQzpjH8H.js} +7 -6
- package/dist/admin/{ConfigurationPage-DiEpF1Rr.mjs → ConfigurationPage-C9CPBfWy.mjs} +186 -6
- package/dist/admin/{ConfigurationPage-D6uya-J1.js → ConfigurationPage-DefuBeYO.js} +191 -11
- package/dist/admin/Content-BttG50Mc.mjs +360 -0
- package/dist/admin/Content-V5MRBsI3.js +362 -0
- package/dist/admin/{CustomBlocksPage-Byt10-6c.mjs → CustomBlocksPage-DB5nnCsn.mjs} +5 -4
- package/dist/admin/{CustomBlocksPage-DP3h_wNd.js → CustomBlocksPage-Dg2rM3F4.js} +8 -7
- package/dist/admin/EntryWidgets-B8YA0Zxy.mjs +199 -0
- package/dist/admin/EntryWidgets-BcXAAx3F.js +201 -0
- package/dist/admin/{MentionsWidget-sMkM9mHX.mjs → MentionsWidget-CJPZDk9Z.mjs} +2 -2
- package/dist/admin/{MentionsWidget-C2OCAmqq.js → MentionsWidget-DUz6YVIG.js} +2 -2
- package/dist/admin/{useT-CLPhBmBC.mjs → SectionCard-8ZNHkvn9.mjs} +2 -12
- package/dist/admin/{useT-BXJLIPN4.js → SectionCard-Bs-xiiH1.js} +0 -10
- package/dist/admin/{TemplatesPage-Yp4OqFE2.mjs → TemplatesPage-VsZ_Mc0R.mjs} +6 -5
- package/dist/admin/{TemplatesPage-DrSJdteI.js → TemplatesPage-dx4_yd_t.js} +13 -12
- package/dist/admin/{api-bix9RLLI.js → api-4AYzwS4-.js} +9 -1
- package/dist/admin/{api-2ZRpHM3d.mjs → api-CcTYyckq.mjs} +9 -1
- package/dist/admin/{de-zcV8D7nt.js → de-B6rdcOqQ.js} +103 -1
- package/dist/admin/{de-1cFMs-4c.mjs → de-BWfR2jTg.mjs} +8 -1
- package/dist/admin/{de-DiCZrmH8.mjs → de-Bip0sBRT.mjs} +19 -1
- package/dist/admin/{de-Dn8athM8.js → de-BrPR4sUB.js} +8 -1
- package/dist/admin/{de-CKz6CG3V.mjs → de-CQA8hOpl.mjs} +103 -1
- package/dist/admin/{de-CbBDnXeT.js → de-CnnxKXj7.js} +19 -1
- package/dist/admin/{de-BhhGss1l.js → de-Dss5POqk.js} +12 -1
- package/dist/admin/{de-BNPIGqhs.mjs → de-zgHCYTLH.mjs} +12 -1
- package/dist/admin/{en-CIZ5Ggod.js → en--JjAHbpP.js} +8 -1
- package/dist/admin/{en-cYzqbASF.mjs → en-BCKaVgBM.mjs} +103 -1
- package/dist/admin/{en-B9ApE1y1.js → en-CJ17Sp_e.js} +12 -1
- package/dist/admin/{en-BMWhILnj.js → en-CbGkcq0Q.js} +103 -1
- package/dist/admin/{en-DCPMqFIa.mjs → en-Cd6Jk-J0.mjs} +19 -1
- package/dist/admin/{en-CpehF0Kv.js → en-D69Fe9ZO.js} +19 -1
- package/dist/admin/{en-Dc9y-6n9.mjs → en-Dr58wBAo.mjs} +8 -1
- package/dist/admin/{en-gFLeK9Ng.mjs → en-Uhm7OouM.mjs} +12 -1
- package/dist/admin/entry-panel-events-0msyPrAD.js +18 -0
- package/dist/admin/entry-panel-events-XRuUoLZ9.mjs +19 -0
- package/dist/admin/{es-D2Kw6E4N.mjs → es-B2Hkkbw9.mjs} +8 -1
- package/dist/admin/{es-BmwBgEgz.mjs → es-BMkmfH88.mjs} +12 -1
- package/dist/admin/{es-Chs37IBR.mjs → es-Bz8d72Fa.mjs} +19 -1
- package/dist/admin/{es-CQPh8PXw.js → es-C8UotT8O.js} +103 -1
- package/dist/admin/{es-CawpzwyC.js → es-CcEDZpVQ.js} +19 -1
- package/dist/admin/{es-C0W31rl8.js → es-DJm3HFJt.js} +12 -1
- package/dist/admin/{es-C4IRHV5d.js → es-YvaTAtqY.js} +8 -1
- package/dist/admin/{es-DCamt1ek.mjs → es-pvPfNAld.mjs} +103 -1
- package/dist/admin/{fr-BOvvfEH7.mjs → fr-BvPjRiwr.mjs} +8 -1
- package/dist/admin/{fr-Dp5-XP29.mjs → fr-CKHZ0xxU.mjs} +19 -1
- package/dist/admin/{fr-iGeIfEcU.js → fr-CRM9VuAq.js} +12 -1
- package/dist/admin/{fr-CMWBNE5D.mjs → fr-CrIHmKYX.mjs} +12 -1
- package/dist/admin/{fr-COOsqexl.js → fr-Cx29jQ_g.js} +19 -1
- package/dist/admin/{fr-oW0t8bT5.mjs → fr-D4tL6Ag2.mjs} +103 -1
- package/dist/admin/{fr-Zkb8vfjN.js → fr-Di-U-rAH.js} +8 -1
- package/dist/admin/{fr-DpC44Ol8.js → fr-DrUYv2jh.js} +103 -1
- package/dist/admin/{index-BVjf1gVC.mjs → index-C4ksUkEm.mjs} +9183 -6353
- package/dist/admin/{index-64wc26Bl.js → index-C5D3VqLq.js} +9170 -6340
- package/dist/admin/{index-D_Fv8Non.mjs → index-CMYCZWOh.mjs} +1053 -190
- package/dist/admin/{index-D6Z7i8ba.js → index-DRyctF9s.js} +961 -98
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/{math-vsK_06ZR.js → math-D6jmskGS.js} +1 -1
- package/dist/admin/{math-CIQ4Z_mY.mjs → math-DntdSWKX.mjs} +1 -1
- package/dist/admin/{pt-DALDvfBn.mjs → pt-B8x7v-Xw.mjs} +19 -1
- package/dist/admin/{pt-DXy7G1x7.js → pt-BYn2xx78.js} +19 -1
- package/dist/admin/{pt-Bo0Pm_Pt.js → pt-CojQcz-p.js} +103 -1
- package/dist/admin/{pt-uGpfRQLC.mjs → pt-CuoIihKx.mjs} +103 -1
- package/dist/admin/{pt-1IUyx6ae.js → pt-CzrN_3ui.js} +8 -1
- package/dist/admin/{pt-DFNgZ5_k.mjs → pt-DDlPJYtB.mjs} +12 -1
- package/dist/admin/{pt-BHmXk2d9.js → pt-DPVAycXJ.js} +12 -1
- package/dist/admin/{pt-etwsg3G4.mjs → pt-DdGagO99.mjs} +8 -1
- package/dist/admin/useT-Bpw__IXT.js +12 -0
- package/dist/admin/useT-Cb-R3kyA.mjs +13 -0
- package/dist/blocks/index.d.mts +124 -0
- package/dist/blocks/index.d.ts +124 -0
- package/dist/blocks/index.js +172 -3
- package/dist/blocks/index.mjs +172 -3
- package/dist/math/index.js +6 -2
- package/dist/math/index.mjs +6 -2
- package/dist/react/index.js +1376 -1067
- package/dist/react/index.mjs +1376 -1067
- package/dist/render/index.d.mts +22 -0
- package/dist/render/index.d.ts +22 -0
- package/dist/render/index.js +1376 -1067
- package/dist/render/index.mjs +1376 -1067
- package/dist/server/index.js +28894 -24197
- package/dist/server/index.mjs +28893 -24196
- package/dist/server/mcp-worker.js +11319 -0
- package/dist/vue/index.js +1376 -1067
- package/dist/vue/index.mjs +1376 -1067
- package/package.json +7 -7
- package/schema/magic-editor-x.schema.json +9 -1
- package/types/blocks.d.ts +124 -0
- package/types/index.d.ts +10 -1
- package/types/render.d.ts +22 -0
package/dist/react/index.js
CHANGED
|
@@ -384,11 +384,15 @@ var FOOTNOTE_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
|
384
384
|
var MAX_MATH_TEX = 1e4;
|
|
385
385
|
var MAX_INLINE_TEX = 2e3;
|
|
386
386
|
var MAX_FOOTNOTE_NOTE = 4e3;
|
|
387
|
+
var INLINE_FORMAT_ATTRIBUTES = Object.freeze({
|
|
388
|
+
span: ["data-mex-color", "data-mex-annotation", "data-mex-a-*"],
|
|
389
|
+
mark: ["data-mex-highlight"]
|
|
390
|
+
});
|
|
387
391
|
var INLINE_ATTRIBUTES = Object.freeze({
|
|
388
392
|
a: ["href", "target", "rel", "title", ...INTERNAL_LINK_ATTRIBUTES],
|
|
389
|
-
span: ["class", "data-tooltip", MATH_ATTRIBUTE],
|
|
393
|
+
span: ["class", "data-tooltip", MATH_ATTRIBUTE, ...INLINE_FORMAT_ATTRIBUTES.span],
|
|
390
394
|
sup: [...FOOTNOTE_ATTRIBUTES],
|
|
391
|
-
mark: ["class"],
|
|
395
|
+
mark: ["class", ...INLINE_FORMAT_ATTRIBUTES.mark],
|
|
392
396
|
u: ["class"],
|
|
393
397
|
s: ["class"],
|
|
394
398
|
code: ["class"]
|
|
@@ -705,6 +709,9 @@ var BLOCK_POLICIES = {
|
|
|
705
709
|
if (typeof file.extension === "string") cleanFile.extension = plain(file.extension, 16);
|
|
706
710
|
if (Number.isFinite(file.size)) cleanFile.size = file.size;
|
|
707
711
|
if (typeof file.title === "string") cleanFile.title = plain(file.title, 255);
|
|
712
|
+
if (file.id !== void 0 && (Number.isInteger(file.id) || typeof file.id === "string"))
|
|
713
|
+
cleanFile.id = file.id;
|
|
714
|
+
if (typeof file.documentId === "string") cleanFile.documentId = plain(file.documentId, 64);
|
|
708
715
|
return { file: cleanFile, title: plain(d.title, 255) };
|
|
709
716
|
},
|
|
710
717
|
embed: (d, inline) => ({
|
|
@@ -862,569 +869,901 @@ var nodesTextContent = (nodes) => {
|
|
|
862
869
|
return out;
|
|
863
870
|
};
|
|
864
871
|
|
|
865
|
-
// shared/
|
|
866
|
-
var
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
"
|
|
872
|
-
"
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
"
|
|
880
|
-
"
|
|
881
|
-
"
|
|
882
|
-
"
|
|
883
|
-
"
|
|
872
|
+
// shared/inline-format.mjs
|
|
873
|
+
var TOKEN_PATTERN = /^[a-z][a-z0-9-]{0,31}$/;
|
|
874
|
+
var COLOR_ATTRIBUTE = "data-mex-color";
|
|
875
|
+
var HIGHLIGHT_ATTRIBUTE = "data-mex-highlight";
|
|
876
|
+
var PALETTE_LIMITS = Object.freeze({ tokens: 24, label: 60, locales: 20 });
|
|
877
|
+
var DEFAULT_SURFACE = Object.freeze({
|
|
878
|
+
background: Object.freeze({ light: "#ffffff", dark: "#121212" }),
|
|
879
|
+
text: Object.freeze({ light: "#1f1f1f", dark: "#f2f2f2" })
|
|
880
|
+
});
|
|
881
|
+
var colorClass = (token) => `mex-color-${token}`;
|
|
882
|
+
var highlightClass = (token) => `mex-highlight-${token}`;
|
|
883
|
+
|
|
884
|
+
// shared/blocks/define.mjs
|
|
885
|
+
var BLOCK_FIELD_TYPES = Object.freeze([
|
|
886
|
+
"text",
|
|
887
|
+
"inline",
|
|
888
|
+
"url",
|
|
889
|
+
"enum",
|
|
890
|
+
"number",
|
|
891
|
+
"boolean",
|
|
892
|
+
"array",
|
|
893
|
+
"object"
|
|
884
894
|
]);
|
|
885
|
-
var
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
ldquo: "\u201C",
|
|
907
|
-
rdquo: "\u201D",
|
|
908
|
-
laquo: "\xAB",
|
|
909
|
-
raquo: "\xBB",
|
|
910
|
-
euro: "\u20AC",
|
|
911
|
-
middot: "\xB7",
|
|
912
|
-
bull: "\u2022",
|
|
913
|
-
times: "\xD7",
|
|
914
|
-
deg: "\xB0",
|
|
915
|
-
tab: " ",
|
|
916
|
-
newline: "\n",
|
|
917
|
-
colon: ":",
|
|
918
|
-
sol: "/",
|
|
919
|
-
lpar: "(",
|
|
920
|
-
rpar: ")"
|
|
895
|
+
var BLOCK_LIMITS = Object.freeze({
|
|
896
|
+
/** Fields per object (also the schema root). */
|
|
897
|
+
maxFields: 50,
|
|
898
|
+
/** Nesting of arrays and objects below the root. */
|
|
899
|
+
maxDepth: 4,
|
|
900
|
+
/** Largest `max` of a text or inline field. */
|
|
901
|
+
maxText: 1e5,
|
|
902
|
+
/** Default `max` of a text field. */
|
|
903
|
+
defaultText: 1e3,
|
|
904
|
+
/** Default `max` of an inline HTML field. */
|
|
905
|
+
defaultInline: 1e4,
|
|
906
|
+
/** Largest `max` of an array field. */
|
|
907
|
+
maxItems: 500,
|
|
908
|
+
/** Default `max` of an array field. */
|
|
909
|
+
defaultItems: 50,
|
|
910
|
+
/** Values of an enum field. */
|
|
911
|
+
maxEnumValues: 100,
|
|
912
|
+
/** Values cleaned per block; later array items are dropped. */
|
|
913
|
+
maxValues: 2e4,
|
|
914
|
+
/** Length of a URL value. */
|
|
915
|
+
maxUrl: 2048
|
|
921
916
|
});
|
|
922
|
-
var
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
917
|
+
var BLOCK_PRESETS = Object.freeze(["article", "basic", "minimal"]);
|
|
918
|
+
var RESERVED_BLOCK_NAMES = Object.freeze([
|
|
919
|
+
"paragraph",
|
|
920
|
+
"header",
|
|
921
|
+
"list",
|
|
922
|
+
"checklist",
|
|
923
|
+
"quote",
|
|
924
|
+
"warning",
|
|
925
|
+
"alert",
|
|
926
|
+
"toggle",
|
|
927
|
+
"code",
|
|
928
|
+
"codeFlask",
|
|
929
|
+
"delimiter",
|
|
930
|
+
"toc",
|
|
931
|
+
"synced",
|
|
932
|
+
"table",
|
|
933
|
+
"embed",
|
|
934
|
+
"raw",
|
|
935
|
+
"image",
|
|
936
|
+
"simpleImage",
|
|
937
|
+
"gallery",
|
|
938
|
+
"video",
|
|
939
|
+
"audio",
|
|
940
|
+
"linkTool",
|
|
941
|
+
"attaches",
|
|
942
|
+
"personality",
|
|
943
|
+
"button",
|
|
944
|
+
"mediaLib",
|
|
945
|
+
"embeddedEntry",
|
|
946
|
+
"bold",
|
|
947
|
+
"italic",
|
|
948
|
+
"hyperlink",
|
|
949
|
+
"mention",
|
|
950
|
+
"marker",
|
|
951
|
+
"underline",
|
|
952
|
+
"strikethrough",
|
|
953
|
+
"inlineCode",
|
|
954
|
+
"tooltip",
|
|
955
|
+
"aiAssistant",
|
|
956
|
+
"alignmentTune",
|
|
957
|
+
"textVariant",
|
|
958
|
+
"indentTune"
|
|
959
|
+
]);
|
|
960
|
+
var SDK_COMPATIBLE_NAMES = Object.freeze(["math"]);
|
|
961
|
+
var RESERVED = new Set(RESERVED_BLOCK_NAMES.map((name) => name.toLowerCase()));
|
|
962
|
+
var BLOCK_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{1,49}$/;
|
|
963
|
+
var KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
964
|
+
var FORBIDDEN_KEYS2 = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
965
|
+
var DEFINITION_KEYS = /* @__PURE__ */ new Set([
|
|
966
|
+
"name",
|
|
967
|
+
"version",
|
|
968
|
+
"title",
|
|
969
|
+
"description",
|
|
970
|
+
"schema",
|
|
971
|
+
"sanitize",
|
|
972
|
+
"text",
|
|
973
|
+
"markdown",
|
|
974
|
+
"render",
|
|
975
|
+
"presets"
|
|
976
|
+
]);
|
|
977
|
+
var FIELD_KEYS = {
|
|
978
|
+
text: ["max", "multiline", "default"],
|
|
979
|
+
inline: ["max", "default"],
|
|
980
|
+
url: ["schemes", "relative"],
|
|
981
|
+
enum: ["values", "default"],
|
|
982
|
+
number: ["min", "max", "integer", "default"],
|
|
983
|
+
boolean: ["default"],
|
|
984
|
+
array: ["items", "max"],
|
|
985
|
+
object: ["fields"]
|
|
946
986
|
};
|
|
947
|
-
var
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
987
|
+
var BlockDefinitionError = class extends Error {
|
|
988
|
+
/**
|
|
989
|
+
* @param {string} message - Message naming the definition and the problem.
|
|
990
|
+
* @param {string} [code] - `INVALID_DEFINITION` | `RESERVED_NAME` | `NAME_TAKEN` | `REGISTRY_SEALED`.
|
|
991
|
+
*/
|
|
992
|
+
constructor(message, code = "INVALID_DEFINITION") {
|
|
993
|
+
super(message);
|
|
994
|
+
this.name = "BlockDefinitionError";
|
|
995
|
+
this.code = code;
|
|
955
996
|
}
|
|
956
|
-
return -1;
|
|
957
997
|
};
|
|
958
|
-
var
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
for (const name of allowed) {
|
|
962
|
-
if (!Object.prototype.hasOwnProperty.call(attribs, name) || name.startsWith("data-mex-")) continue;
|
|
963
|
-
const value = attribs[name];
|
|
964
|
-
if (name === "href") {
|
|
965
|
-
const url = sanitizeUrl(value);
|
|
966
|
-
if (url) out.href = url;
|
|
967
|
-
} else if (name === "target") {
|
|
968
|
-
const target = sanitizeTarget(value);
|
|
969
|
-
if (target) out.target = target;
|
|
970
|
-
} else if (name === "rel") {
|
|
971
|
-
const rel = String(value).split(/\s+/).filter((token) => /^[a-z-]{1,20}$/.test(token));
|
|
972
|
-
if (rel.length) out.rel = rel.join(" ");
|
|
973
|
-
} else if (name === "class") {
|
|
974
|
-
const classes2 = String(value).split(/\s+/).filter((token) => (INLINE_CLASSES[tag] || []).includes(token));
|
|
975
|
-
if (classes2.length) out.class = classes2.join(" ");
|
|
976
|
-
} else {
|
|
977
|
-
out[name] = String(value).slice(0, 2e3);
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
if (tag === "a" && !options.inNote) Object.assign(out, cleanInternalLinkAttributes(attribs));
|
|
981
|
-
return out;
|
|
998
|
+
var isObject2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
999
|
+
var fail = (where, message) => {
|
|
1000
|
+
throw new BlockDefinitionError(`Magic Editor X block ${where}: ${message}`);
|
|
982
1001
|
};
|
|
983
|
-
var
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
if (node.type !== "element") continue;
|
|
989
|
-
if (isMathNode(node)) {
|
|
990
|
-
const tex = nodesToText(node.children, { raw: true }).replace(/\u200b/g, "").slice(0, MAX_INLINE_TEX);
|
|
991
|
-
node.children = tex ? [{ type: "text", value: tex }] : [];
|
|
992
|
-
} else if (isFootnoteNode(node)) {
|
|
993
|
-
const text = nodesToText(node.children, { raw: true }).slice(0, MAX_MARKER_TEXT);
|
|
994
|
-
node.children = text ? [{ type: "text", value: text }] : [];
|
|
995
|
-
} else if (depth < MAX_DEPTH) finalizeSpecial(node.children, depth + 1);
|
|
996
|
-
}
|
|
997
|
-
return nodes;
|
|
1002
|
+
var boundedInt = (value, min, max, fallback, where, key) => {
|
|
1003
|
+
if (value === void 0) return fallback;
|
|
1004
|
+
if (!Number.isInteger(value) || value < min || value > max)
|
|
1005
|
+
fail(where, `"${key}" must be an integer from ${min} to ${max}`);
|
|
1006
|
+
return value;
|
|
998
1007
|
};
|
|
999
|
-
var
|
|
1000
|
-
if (
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1008
|
+
var normalizeField = (input, where, depth) => {
|
|
1009
|
+
if (!isObject2(input)) fail(where, 'a field must be an object with a "type"');
|
|
1010
|
+
const type = input.type;
|
|
1011
|
+
if (!BLOCK_FIELD_TYPES.includes(type)) fail(where, `unknown field type ${JSON.stringify(type)}`);
|
|
1012
|
+
for (const key of Object.keys(input))
|
|
1013
|
+
if (key !== "type" && key !== "label" && !FIELD_KEYS[type].includes(key))
|
|
1014
|
+
fail(where, `unknown option "${key}" for a ${type} field`);
|
|
1015
|
+
const out = { type };
|
|
1016
|
+
if (input.label !== void 0) {
|
|
1017
|
+
if (typeof input.label !== "string" || input.label.length > 100)
|
|
1018
|
+
fail(where, '"label" must be a string of at most 100 characters');
|
|
1019
|
+
out.label = input.label;
|
|
1010
1020
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
};
|
|
1031
|
-
let i = 0;
|
|
1032
|
-
while (i < html.length) {
|
|
1033
|
-
const lt = html.indexOf("<", i);
|
|
1034
|
-
if (lt === -1) {
|
|
1035
|
-
text += html.slice(i);
|
|
1021
|
+
switch (type) {
|
|
1022
|
+
case "text":
|
|
1023
|
+
case "inline": {
|
|
1024
|
+
out.max = boundedInt(
|
|
1025
|
+
input.max,
|
|
1026
|
+
1,
|
|
1027
|
+
BLOCK_LIMITS.maxText,
|
|
1028
|
+
type === "text" ? BLOCK_LIMITS.defaultText : BLOCK_LIMITS.defaultInline,
|
|
1029
|
+
where,
|
|
1030
|
+
"max"
|
|
1031
|
+
);
|
|
1032
|
+
if (input.default !== void 0 && typeof input.default !== "string")
|
|
1033
|
+
fail(where, '"default" must be a string');
|
|
1034
|
+
out.default = (input.default || "").slice(0, out.max);
|
|
1035
|
+
if (type === "text") {
|
|
1036
|
+
if (input.multiline !== void 0 && typeof input.multiline !== "boolean")
|
|
1037
|
+
fail(where, '"multiline" must be a boolean');
|
|
1038
|
+
out.multiline = input.multiline === true;
|
|
1039
|
+
}
|
|
1036
1040
|
break;
|
|
1037
1041
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
const end2 = html.indexOf("]]>", i + 9);
|
|
1048
|
-
flush();
|
|
1049
|
-
i = end2 === -1 ? html.length : end2 + 3;
|
|
1050
|
-
continue;
|
|
1051
|
-
}
|
|
1052
|
-
if (html[i + 1] === "!" || html[i + 1] === "?") {
|
|
1053
|
-
const end2 = html.indexOf(">", i + 2);
|
|
1054
|
-
flush();
|
|
1055
|
-
i = end2 === -1 ? html.length : end2 + 1;
|
|
1056
|
-
continue;
|
|
1057
|
-
}
|
|
1058
|
-
const closing = html[i + 1] === "/";
|
|
1059
|
-
const nameMatch = /^[A-Za-z][A-Za-z0-9-]{0,40}/.exec(html.slice(i + (closing ? 2 : 1), i + 45));
|
|
1060
|
-
if (!nameMatch) {
|
|
1061
|
-
text += "<";
|
|
1062
|
-
i += 1;
|
|
1063
|
-
continue;
|
|
1042
|
+
case "url": {
|
|
1043
|
+
const schemes = input.schemes === void 0 ? ["http", "https"] : input.schemes;
|
|
1044
|
+
if (!Array.isArray(schemes) || !schemes.length || schemes.some((scheme) => !LINK_SCHEMES.includes(scheme)))
|
|
1045
|
+
fail(where, `"schemes" must be a non-empty list of ${LINK_SCHEMES.join(", ")}`);
|
|
1046
|
+
if (input.relative !== void 0 && typeof input.relative !== "boolean")
|
|
1047
|
+
fail(where, '"relative" must be a boolean');
|
|
1048
|
+
out.schemes = Object.freeze([...new Set(schemes)]);
|
|
1049
|
+
out.relative = input.relative !== false;
|
|
1050
|
+
break;
|
|
1064
1051
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1052
|
+
case "enum": {
|
|
1053
|
+
const values = input.values;
|
|
1054
|
+
if (!Array.isArray(values) || values.length < 1 || values.length > BLOCK_LIMITS.maxEnumValues || values.some((value) => typeof value !== "string" || value.length < 1 || value.length > 100) || new Set(values).size !== values.length)
|
|
1055
|
+
fail(
|
|
1056
|
+
where,
|
|
1057
|
+
`"values" must be 1 to ${BLOCK_LIMITS.maxEnumValues} distinct strings (1-100 characters)`
|
|
1058
|
+
);
|
|
1059
|
+
out.values = Object.freeze([...values]);
|
|
1060
|
+
if (input.default !== void 0 && !values.includes(input.default))
|
|
1061
|
+
fail(where, '"default" must be one of "values"');
|
|
1062
|
+
out.default = input.default === void 0 ? values[0] : input.default;
|
|
1068
1063
|
break;
|
|
1069
1064
|
}
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1065
|
+
case "number": {
|
|
1066
|
+
for (const key of ["min", "max", "default"])
|
|
1067
|
+
if (input[key] !== void 0 && (typeof input[key] !== "number" || !Number.isFinite(input[key])))
|
|
1068
|
+
fail(where, `"${key}" must be a finite number`);
|
|
1069
|
+
if (input.integer !== void 0 && typeof input.integer !== "boolean")
|
|
1070
|
+
fail(where, '"integer" must be a boolean');
|
|
1071
|
+
out.integer = input.integer === true;
|
|
1072
|
+
out.min = input.min === void 0 ? -Number.MAX_SAFE_INTEGER : input.min;
|
|
1073
|
+
out.max = input.max === void 0 ? Number.MAX_SAFE_INTEGER : input.max;
|
|
1074
|
+
if (out.min > out.max) fail(where, '"min" must not be greater than "max"');
|
|
1075
|
+
if (input.default !== void 0) {
|
|
1076
|
+
if (input.default < out.min || input.default > out.max || out.integer && !Number.isInteger(input.default))
|
|
1077
|
+
fail(where, '"default" must be a valid value of the field');
|
|
1078
|
+
out.default = input.default;
|
|
1081
1079
|
}
|
|
1082
|
-
|
|
1083
|
-
}
|
|
1084
|
-
if (DROP_WITH_CONTENT.has(tag)) {
|
|
1085
|
-
const selfClosing = /\/\s*$/.test(body);
|
|
1086
|
-
if (selfClosing) continue;
|
|
1087
|
-
const closeIndex = html.slice(i).search(new RegExp(`</${tag}[\\s/>]`, "i"));
|
|
1088
|
-
if (closeIndex === -1) break;
|
|
1089
|
-
const closeEnd = html.indexOf(">", i + closeIndex);
|
|
1090
|
-
i = closeEnd === -1 ? html.length : closeEnd + 1;
|
|
1091
|
-
continue;
|
|
1080
|
+
break;
|
|
1092
1081
|
}
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1082
|
+
case "boolean":
|
|
1083
|
+
if (input.default !== void 0 && typeof input.default !== "boolean")
|
|
1084
|
+
fail(where, '"default" must be a boolean');
|
|
1085
|
+
out.default = input.default === true;
|
|
1086
|
+
break;
|
|
1087
|
+
case "array":
|
|
1088
|
+
if (depth >= BLOCK_LIMITS.maxDepth) fail(where, `fields nest at most ${BLOCK_LIMITS.maxDepth} levels`);
|
|
1089
|
+
out.max = boundedInt(input.max, 1, BLOCK_LIMITS.maxItems, BLOCK_LIMITS.defaultItems, where, "max");
|
|
1090
|
+
out.items = normalizeField(input.items, `${where}[]`, depth + 1);
|
|
1091
|
+
break;
|
|
1092
|
+
case "object":
|
|
1093
|
+
if (depth >= BLOCK_LIMITS.maxDepth) fail(where, `fields nest at most ${BLOCK_LIMITS.maxDepth} levels`);
|
|
1094
|
+
out.fields = normalizeFields(input.fields, where, depth + 1);
|
|
1095
|
+
break;
|
|
1096
|
+
default:
|
|
1097
|
+
break;
|
|
1106
1098
|
}
|
|
1107
|
-
|
|
1108
|
-
return finalizeSpecial(root.children);
|
|
1099
|
+
return Object.freeze(out);
|
|
1109
1100
|
};
|
|
1110
|
-
var
|
|
1111
|
-
if (
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
...isMentionLink(attrs) ? { mention: true } : {}
|
|
1121
|
-
});
|
|
1122
|
-
} catch {
|
|
1123
|
-
result = void 0;
|
|
1101
|
+
var normalizeFields = (input, where, depth) => {
|
|
1102
|
+
if (!isObject2(input)) fail(where, '"fields" must be an object of field descriptors');
|
|
1103
|
+
const keys = Object.keys(input);
|
|
1104
|
+
if (keys.length < 1 || keys.length > BLOCK_LIMITS.maxFields)
|
|
1105
|
+
fail(where, `an object needs 1 to ${BLOCK_LIMITS.maxFields} fields`);
|
|
1106
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
1107
|
+
for (const key of keys) {
|
|
1108
|
+
if (!KEY_PATTERN.test(key) || FORBIDDEN_KEYS2.has(key))
|
|
1109
|
+
fail(where, `field name ${JSON.stringify(key)} must match ${KEY_PATTERN}`);
|
|
1110
|
+
out[key] = normalizeField(input[key], `${where}.${key}`, depth);
|
|
1124
1111
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1112
|
+
return Object.freeze(out);
|
|
1113
|
+
};
|
|
1114
|
+
var blockNameProblem = (name) => {
|
|
1115
|
+
if (typeof name !== "string" || !BLOCK_NAME_PATTERN.test(name))
|
|
1116
|
+
return `the name must match ${BLOCK_NAME_PATTERN}`;
|
|
1117
|
+
if (RESERVED.has(name.toLowerCase())) return `"${name}" is a built-in tool name`;
|
|
1118
|
+
return null;
|
|
1119
|
+
};
|
|
1120
|
+
var defineBlock = (definition) => {
|
|
1121
|
+
if (!isObject2(definition))
|
|
1122
|
+
throw new BlockDefinitionError("Magic Editor X block: the definition must be an object");
|
|
1123
|
+
const label3 = typeof definition.name === "string" ? `"${definition.name.slice(0, 50)}"` : "(no name)";
|
|
1124
|
+
for (const key of Object.keys(definition))
|
|
1125
|
+
if (!DEFINITION_KEYS.has(key)) fail(label3, `unknown key "${key}"`);
|
|
1126
|
+
const problem = blockNameProblem(definition.name);
|
|
1127
|
+
if (problem)
|
|
1128
|
+
throw new BlockDefinitionError(
|
|
1129
|
+
`Magic Editor X block ${label3}: ${problem}`,
|
|
1130
|
+
problem.includes("built-in") ? "RESERVED_NAME" : "INVALID_DEFINITION"
|
|
1131
|
+
);
|
|
1132
|
+
const out = {
|
|
1133
|
+
name: definition.name,
|
|
1134
|
+
version: boundedInt(definition.version, 1, 1e6, 1, label3, "version")
|
|
1135
|
+
};
|
|
1136
|
+
for (const [key, max] of [
|
|
1137
|
+
["title", 100],
|
|
1138
|
+
["description", 500]
|
|
1139
|
+
]) {
|
|
1140
|
+
if (definition[key] === void 0) continue;
|
|
1141
|
+
if (typeof definition[key] !== "string" || definition[key].length > max)
|
|
1142
|
+
fail(label3, `"${key}" must be a string of at most ${max} characters`);
|
|
1143
|
+
out[key] = definition[key];
|
|
1129
1144
|
}
|
|
1130
|
-
|
|
1145
|
+
out.schema = normalizeFields(definition.schema, `${label3} schema`, 0);
|
|
1146
|
+
for (const key of ["sanitize", "text", "markdown", "render"]) {
|
|
1147
|
+
if (definition[key] === void 0) continue;
|
|
1148
|
+
if (typeof definition[key] !== "function") fail(label3, `"${key}" must be a function`);
|
|
1149
|
+
out[key] = definition[key];
|
|
1150
|
+
}
|
|
1151
|
+
const presets = definition.presets === void 0 ? [] : definition.presets;
|
|
1152
|
+
if (!Array.isArray(presets) || presets.some((preset) => !BLOCK_PRESETS.includes(preset)))
|
|
1153
|
+
fail(label3, `"presets" must list some of ${BLOCK_PRESETS.join(", ")}`);
|
|
1154
|
+
out.presets = Object.freeze([...new Set(presets)]);
|
|
1155
|
+
return Object.freeze(out);
|
|
1131
1156
|
};
|
|
1132
|
-
var
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
if (node.tag === "br") {
|
|
1159
|
-
out.push({ type: "element", tag: "br", attrs: {}, children: [] });
|
|
1160
|
-
continue;
|
|
1161
|
-
}
|
|
1162
|
-
if (isMathNode(node)) {
|
|
1163
|
-
const tex = nodesToText(node.children);
|
|
1164
|
-
if (state && !options.storage) {
|
|
1165
|
-
if (tex.trim()) out.push(state.math(tex, false));
|
|
1166
|
-
continue;
|
|
1157
|
+
var cleanValue = (field, value, inline, budget) => {
|
|
1158
|
+
budget.left -= 1;
|
|
1159
|
+
switch (field.type) {
|
|
1160
|
+
case "text":
|
|
1161
|
+
return typeof value === "string" ? value.slice(0, field.max) : field.default;
|
|
1162
|
+
case "inline":
|
|
1163
|
+
return inline(typeof value === "string" ? value.slice(0, field.max) : field.default);
|
|
1164
|
+
case "url":
|
|
1165
|
+
return typeof value === "string" ? sanitizeUrl(value.slice(0, BLOCK_LIMITS.maxUrl), {
|
|
1166
|
+
schemes: field.schemes,
|
|
1167
|
+
allowRelative: field.relative
|
|
1168
|
+
}) : "";
|
|
1169
|
+
case "enum":
|
|
1170
|
+
return typeof value === "string" && field.values.includes(value) ? value : field.default;
|
|
1171
|
+
case "number":
|
|
1172
|
+
return typeof value === "number" && Number.isFinite(value) && value >= field.min && value <= field.max && (!field.integer || Number.isInteger(value)) ? value : field.default;
|
|
1173
|
+
case "boolean":
|
|
1174
|
+
return typeof value === "boolean" ? value : field.default;
|
|
1175
|
+
case "array": {
|
|
1176
|
+
const out = [];
|
|
1177
|
+
if (!Array.isArray(value)) return out;
|
|
1178
|
+
for (const item of value) {
|
|
1179
|
+
if (out.length >= field.max || budget.left <= 0) break;
|
|
1180
|
+
if (!matchesType(field.items, item)) continue;
|
|
1181
|
+
const clean2 = cleanValue(field.items, item, inline, budget);
|
|
1182
|
+
if (clean2 !== void 0) out.push(clean2);
|
|
1167
1183
|
}
|
|
1168
|
-
out
|
|
1169
|
-
type: "element",
|
|
1170
|
-
tag: "span",
|
|
1171
|
-
attrs: { [MATH_ATTRIBUTE]: "true" },
|
|
1172
|
-
children: tex ? [{ type: "text", value: tex }] : []
|
|
1173
|
-
});
|
|
1174
|
-
continue;
|
|
1184
|
+
return out;
|
|
1175
1185
|
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1186
|
+
case "object":
|
|
1187
|
+
return cleanObject(field.fields, isObject2(value) ? value : {}, inline, budget);
|
|
1188
|
+
default:
|
|
1189
|
+
return void 0;
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
var matchesType = (field, item) => {
|
|
1193
|
+
switch (field.type) {
|
|
1194
|
+
case "text":
|
|
1195
|
+
case "inline":
|
|
1196
|
+
case "url":
|
|
1197
|
+
case "enum":
|
|
1198
|
+
return typeof item === "string";
|
|
1199
|
+
case "number":
|
|
1200
|
+
return typeof item === "number";
|
|
1201
|
+
case "boolean":
|
|
1202
|
+
return typeof item === "boolean";
|
|
1203
|
+
case "array":
|
|
1204
|
+
return Array.isArray(item);
|
|
1205
|
+
default:
|
|
1206
|
+
return isObject2(item);
|
|
1207
|
+
}
|
|
1208
|
+
};
|
|
1209
|
+
var cleanObject = (fields, value, inline, budget) => {
|
|
1210
|
+
const out = {};
|
|
1211
|
+
for (const key of Object.keys(fields)) {
|
|
1212
|
+
const own = Object.prototype.hasOwnProperty.call(value, key) ? value[key] : void 0;
|
|
1213
|
+
const clean2 = cleanValue(fields[key], own, inline, budget);
|
|
1214
|
+
if (clean2 !== void 0) out[key] = clean2;
|
|
1215
|
+
}
|
|
1216
|
+
return out;
|
|
1217
|
+
};
|
|
1218
|
+
var eachLeaf = (fields, data, visit) => {
|
|
1219
|
+
const walk = (field, value, path, depth) => {
|
|
1220
|
+
if (depth > BLOCK_LIMITS.maxDepth + 1) return;
|
|
1221
|
+
if (field.type === "array") {
|
|
1222
|
+
if (!Array.isArray(value)) return;
|
|
1223
|
+
value.slice(0, field.max).forEach((item, index) => walk(field.items, item, [...path, index], depth + 1));
|
|
1224
|
+
} else if (field.type === "object") {
|
|
1225
|
+
if (!isObject2(value)) return;
|
|
1226
|
+
for (const key of Object.keys(field.fields))
|
|
1227
|
+
if (Object.prototype.hasOwnProperty.call(value, key))
|
|
1228
|
+
walk(field.fields[key], value[key], [...path, key], depth + 1);
|
|
1229
|
+
} else visit(field, value, path);
|
|
1230
|
+
};
|
|
1231
|
+
if (!isObject2(data)) return;
|
|
1232
|
+
for (const key of Object.keys(fields))
|
|
1233
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) walk(fields[key], data[key], [key], 0);
|
|
1234
|
+
};
|
|
1235
|
+
var fieldAt = (fields, path) => {
|
|
1236
|
+
let current = { type: "object", fields };
|
|
1237
|
+
for (const part of String(path).split(".")) {
|
|
1238
|
+
if (!part) continue;
|
|
1239
|
+
if (current.type === "array") {
|
|
1240
|
+
if (/^\d+$/.test(part)) {
|
|
1241
|
+
current = current.items;
|
|
1179
1242
|
continue;
|
|
1180
1243
|
}
|
|
1181
|
-
|
|
1182
|
-
const note = storedNote(node.note);
|
|
1183
|
-
if (note) attrs2["data-mex-note"] = note;
|
|
1184
|
-
out.push({ type: "element", tag: "sup", attrs: attrs2, children: inlineNodesToRender(node.children, options) });
|
|
1185
|
-
continue;
|
|
1244
|
+
return null;
|
|
1186
1245
|
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1246
|
+
if (current.type !== "object" || !Object.prototype.hasOwnProperty.call(current.fields, part)) return null;
|
|
1247
|
+
current = current.fields[part];
|
|
1248
|
+
}
|
|
1249
|
+
return current;
|
|
1250
|
+
};
|
|
1251
|
+
var compiled = /* @__PURE__ */ new WeakMap();
|
|
1252
|
+
var compileBlock = (definition) => {
|
|
1253
|
+
if (definition && typeof definition === "object" && compiled.has(definition))
|
|
1254
|
+
return compiled.get(definition);
|
|
1255
|
+
const def = defineBlock(definition && typeof definition === "object" ? { ...definition } : definition);
|
|
1256
|
+
const schema = def.schema;
|
|
1257
|
+
const run = (data, inline) => cleanObject(schema, isObject2(data) ? data : {}, inline, { left: BLOCK_LIMITS.maxValues });
|
|
1258
|
+
const result = Object.freeze({
|
|
1259
|
+
...def,
|
|
1260
|
+
/**
|
|
1261
|
+
* Cleans untrusted block data (unknown keys dropped, values bounded).
|
|
1262
|
+
* The optional `sanitize` hook runs on the clean data; its result is
|
|
1263
|
+
* cleaned again, so it cannot add keys or unsafe values. A hook that
|
|
1264
|
+
* throws is ignored (the clean data is used).
|
|
1265
|
+
* @param {unknown} data - Block data.
|
|
1266
|
+
* @param {(html: string) => string} inline - Inline HTML sanitiser of the caller.
|
|
1267
|
+
* @returns {object} Clean data.
|
|
1268
|
+
*/
|
|
1269
|
+
clean: (data, inline) => {
|
|
1270
|
+
const first = run(data, inline);
|
|
1271
|
+
if (!def.sanitize) return first;
|
|
1272
|
+
let next;
|
|
1273
|
+
try {
|
|
1274
|
+
next = def.sanitize(copyData(first), { sanitizeUrl });
|
|
1275
|
+
} catch {
|
|
1276
|
+
return first;
|
|
1201
1277
|
}
|
|
1202
|
-
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1278
|
+
return isObject2(next) ? run(next, inline) : first;
|
|
1279
|
+
},
|
|
1280
|
+
/**
|
|
1281
|
+
* Text fields of the data in schema order: `{ path, kind, value }`
|
|
1282
|
+
* (`html` for inline fields, `plain` for text fields).
|
|
1283
|
+
* @param {unknown} data - Block data.
|
|
1284
|
+
* @returns {Array<{ path: Array<string|number>, kind: 'html'|'plain', value: string }>} Fields.
|
|
1285
|
+
*/
|
|
1286
|
+
fields: (data) => {
|
|
1287
|
+
const out = [];
|
|
1288
|
+
eachLeaf(schema, data, (field, value, path) => {
|
|
1289
|
+
if (typeof value !== "string") return;
|
|
1290
|
+
if (field.type === "inline") out.push({ path, kind: "html", value });
|
|
1291
|
+
else if (field.type === "text") out.push({ path, kind: "plain", value });
|
|
1292
|
+
});
|
|
1293
|
+
return out;
|
|
1294
|
+
},
|
|
1295
|
+
/**
|
|
1296
|
+
* Non-empty URL values: `{ path, value }`.
|
|
1297
|
+
* @param {unknown} data - Block data.
|
|
1298
|
+
* @returns {Array<{ path: Array<string|number>, value: string }>} URLs.
|
|
1299
|
+
*/
|
|
1300
|
+
urls: (data) => {
|
|
1301
|
+
const out = [];
|
|
1302
|
+
eachLeaf(schema, data, (field, value, path) => {
|
|
1303
|
+
if (field.type === "url" && typeof value === "string" && value) out.push({ path, value });
|
|
1304
|
+
});
|
|
1305
|
+
return out;
|
|
1306
|
+
},
|
|
1307
|
+
/**
|
|
1308
|
+
* Kind of the value at a dotted path, for the version diff.
|
|
1309
|
+
* @param {string} path - Dotted path.
|
|
1310
|
+
* @returns {'inline'|'plain'|'value'} Kind.
|
|
1311
|
+
*/
|
|
1312
|
+
kindOf: (path) => {
|
|
1313
|
+
const field = fieldAt(schema, path);
|
|
1314
|
+
if (!field) return "value";
|
|
1315
|
+
if (field.type === "inline") return "inline";
|
|
1316
|
+
if (field.type === "text") return "plain";
|
|
1317
|
+
return "value";
|
|
1207
1318
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1319
|
+
});
|
|
1320
|
+
compiled.set(result, result);
|
|
1321
|
+
if (definition && typeof definition === "object") compiled.set(definition, result);
|
|
1322
|
+
return result;
|
|
1323
|
+
};
|
|
1324
|
+
var copyData = (value) => {
|
|
1325
|
+
if (Array.isArray(value)) return value.map(copyData);
|
|
1326
|
+
if (isObject2(value)) {
|
|
1327
|
+
const out = {};
|
|
1328
|
+
for (const [key, child] of Object.entries(value)) out[key] = copyData(child);
|
|
1329
|
+
return out;
|
|
1214
1330
|
}
|
|
1215
|
-
return
|
|
1331
|
+
return value;
|
|
1216
1332
|
};
|
|
1217
|
-
var
|
|
1218
|
-
var
|
|
1219
|
-
|
|
1220
|
-
if (
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
"
|
|
1248
|
-
"
|
|
1249
|
-
"
|
|
1250
|
-
"
|
|
1251
|
-
"
|
|
1252
|
-
"
|
|
1253
|
-
"
|
|
1254
|
-
"
|
|
1255
|
-
"
|
|
1256
|
-
"
|
|
1257
|
-
"
|
|
1258
|
-
"
|
|
1259
|
-
"
|
|
1260
|
-
"
|
|
1261
|
-
"
|
|
1333
|
+
var listCache = /* @__PURE__ */ new WeakMap();
|
|
1334
|
+
var compileBlockList = (list) => {
|
|
1335
|
+
if (!Array.isArray(list)) return /* @__PURE__ */ new Map();
|
|
1336
|
+
if (listCache.has(list)) return listCache.get(list);
|
|
1337
|
+
const map = /* @__PURE__ */ new Map();
|
|
1338
|
+
for (const definition of list) {
|
|
1339
|
+
const def = compileBlock(definition);
|
|
1340
|
+
map.set(def.name, def);
|
|
1341
|
+
}
|
|
1342
|
+
listCache.set(list, map);
|
|
1343
|
+
return map;
|
|
1344
|
+
};
|
|
1345
|
+
|
|
1346
|
+
// shared/blocks/annotations.mjs
|
|
1347
|
+
var ANNOTATION_ATTRIBUTE = "data-mex-annotation";
|
|
1348
|
+
var ANNOTATION_VALUE_PREFIX = "data-mex-a-";
|
|
1349
|
+
var ANNOTATION_NAME = /^[a-z][a-z0-9-]{1,39}$/;
|
|
1350
|
+
var ANNOTATION_KEY = /^[a-z][a-z0-9]{0,23}$/;
|
|
1351
|
+
var ANNOTATION_FIELD_TYPES = Object.freeze(["text", "enum", "url"]);
|
|
1352
|
+
var ANNOTATION_LIMITS = Object.freeze({
|
|
1353
|
+
attributes: 8,
|
|
1354
|
+
text: 1e3,
|
|
1355
|
+
textDefault: 200,
|
|
1356
|
+
values: 50,
|
|
1357
|
+
registered: 50,
|
|
1358
|
+
label: 100,
|
|
1359
|
+
resolveItems: 200
|
|
1360
|
+
});
|
|
1361
|
+
var ANNOTATION_PRESETS = Object.freeze(["full", "article", "basic", "minimal"]);
|
|
1362
|
+
var ANNOTATION_RENDER_TAGS = Object.freeze([
|
|
1363
|
+
"abbr",
|
|
1364
|
+
"dfn",
|
|
1365
|
+
"span",
|
|
1366
|
+
"a",
|
|
1367
|
+
"mark",
|
|
1368
|
+
"cite",
|
|
1369
|
+
"q",
|
|
1370
|
+
"small",
|
|
1371
|
+
"em",
|
|
1372
|
+
"strong",
|
|
1373
|
+
"b",
|
|
1374
|
+
"i",
|
|
1375
|
+
"u",
|
|
1376
|
+
"s",
|
|
1377
|
+
"time",
|
|
1378
|
+
"data",
|
|
1379
|
+
"bdi",
|
|
1380
|
+
"kbd",
|
|
1381
|
+
"var",
|
|
1382
|
+
"ins",
|
|
1383
|
+
"del"
|
|
1262
1384
|
]);
|
|
1263
|
-
var
|
|
1264
|
-
var
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1385
|
+
var ANNOTATION_SHORTCUTS = Object.freeze(["CMD+SHIFT+0", "CMD+SHIFT+1", "CMD+SHIFT+8"]);
|
|
1386
|
+
var ABBREVIATION = "abbreviation";
|
|
1387
|
+
var isObject3 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
1388
|
+
var fail2 = (name, message, code = "INVALID_DEFINITION") => {
|
|
1389
|
+
throw new BlockDefinitionError(`Magic Editor X inline annotation ${name}: ${message}`, code);
|
|
1390
|
+
};
|
|
1391
|
+
var defined = /* @__PURE__ */ new WeakSet();
|
|
1392
|
+
var cleanText = (value, max) => typeof value === "string" ? value.trim().slice(0, max).trim() : "";
|
|
1393
|
+
var normalizeAttribute = (where, input) => {
|
|
1394
|
+
if (!isObject3(input)) fail2(where, 'an attribute must be an object with a "type"');
|
|
1395
|
+
const { type } = input;
|
|
1396
|
+
if (!ANNOTATION_FIELD_TYPES.includes(type)) fail2(where, `unknown attribute type ${JSON.stringify(type)}`);
|
|
1397
|
+
const allowed = { text: ["max"], enum: ["values"], url: ["schemes", "relative"] }[type];
|
|
1398
|
+
for (const key of Object.keys(input))
|
|
1399
|
+
if (!["type", "label", "required", ...allowed].includes(key))
|
|
1400
|
+
fail2(where, `unknown option "${key}" for a ${type} attribute`);
|
|
1401
|
+
const out = { type, required: input.required === true };
|
|
1402
|
+
if (input.label !== void 0) {
|
|
1403
|
+
if (typeof input.label !== "string" || input.label.length > ANNOTATION_LIMITS.label)
|
|
1404
|
+
fail2(where, `"label" must be a string of at most ${ANNOTATION_LIMITS.label} characters`);
|
|
1405
|
+
out.label = input.label;
|
|
1406
|
+
}
|
|
1407
|
+
if (input.required !== void 0 && typeof input.required !== "boolean")
|
|
1408
|
+
fail2(where, '"required" must be a boolean');
|
|
1409
|
+
if (type === "text") {
|
|
1410
|
+
const max = input.max === void 0 ? ANNOTATION_LIMITS.textDefault : input.max;
|
|
1411
|
+
if (!Number.isInteger(max) || max < 1 || max > ANNOTATION_LIMITS.text)
|
|
1412
|
+
fail2(where, `"max" must be an integer from 1 to ${ANNOTATION_LIMITS.text}`);
|
|
1413
|
+
out.max = max;
|
|
1414
|
+
} else if (type === "enum") {
|
|
1415
|
+
const { values } = input;
|
|
1416
|
+
if (!Array.isArray(values) || !values.length || values.length > ANNOTATION_LIMITS.values || !values.every((value) => typeof value === "string" && value.length >= 1 && value.length <= 100) || new Set(values).size !== values.length)
|
|
1417
|
+
fail2(where, `"values" must be 1 to ${ANNOTATION_LIMITS.values} distinct strings`);
|
|
1418
|
+
out.values = Object.freeze([...values]);
|
|
1419
|
+
} else {
|
|
1420
|
+
const schemes = input.schemes === void 0 ? ["http", "https"] : input.schemes;
|
|
1421
|
+
if (!Array.isArray(schemes) || !schemes.length || !schemes.every((scheme) => LINK_SCHEMES.includes(scheme)))
|
|
1422
|
+
fail2(where, `"schemes" must be a non-empty subset of ${LINK_SCHEMES.join(", ")}`);
|
|
1423
|
+
if (input.relative !== void 0 && typeof input.relative !== "boolean")
|
|
1424
|
+
fail2(where, '"relative" must be a boolean');
|
|
1425
|
+
out.schemes = Object.freeze([...new Set(schemes)]);
|
|
1426
|
+
out.relative = input.relative !== false;
|
|
1427
|
+
}
|
|
1428
|
+
return Object.freeze(out);
|
|
1429
|
+
};
|
|
1430
|
+
var defineInlineAnnotation = (definition) => {
|
|
1431
|
+
if (!isObject3(definition)) fail2("(unnamed)", "the definition must be an object");
|
|
1432
|
+
const { name } = definition;
|
|
1433
|
+
if (typeof name !== "string" || !ANNOTATION_NAME.test(name))
|
|
1434
|
+
fail2(JSON.stringify(name), "the name must match /^[a-z][a-z0-9-]{1,39}$/");
|
|
1435
|
+
for (const key of Object.keys(definition))
|
|
1436
|
+
if (!["name", "label", "description", "attributes", "presets", "resolve", "render", "shortcut"].includes(
|
|
1437
|
+
key
|
|
1438
|
+
))
|
|
1439
|
+
fail2(name, `unknown key "${key}"`);
|
|
1440
|
+
for (const key of ["label", "description"])
|
|
1441
|
+
if (definition[key] !== void 0 && (typeof definition[key] !== "string" || definition[key].length > (key === "label" ? 100 : 500)))
|
|
1442
|
+
fail2(name, `"${key}" must be a short string`);
|
|
1443
|
+
if (!isObject3(definition.attributes)) fail2(name, '"attributes" must be an object');
|
|
1444
|
+
const keys = Object.keys(definition.attributes);
|
|
1445
|
+
if (keys.length > ANNOTATION_LIMITS.attributes)
|
|
1446
|
+
fail2(name, `at most ${ANNOTATION_LIMITS.attributes} attributes`);
|
|
1447
|
+
const attributes = {};
|
|
1448
|
+
for (const key of keys) {
|
|
1449
|
+
if (!ANNOTATION_KEY.test(key)) fail2(name, `attribute key "${key}" must match /^[a-z][a-z0-9]{0,23}$/`);
|
|
1450
|
+
attributes[key] = normalizeAttribute(`${name}.${key}`, definition.attributes[key]);
|
|
1451
|
+
}
|
|
1452
|
+
const presets = definition.presets === void 0 ? [] : definition.presets;
|
|
1453
|
+
if (!Array.isArray(presets) || !presets.every((preset) => ANNOTATION_PRESETS.includes(preset)))
|
|
1454
|
+
fail2(name, `"presets" must list only ${ANNOTATION_PRESETS.join(", ")}`);
|
|
1455
|
+
if (definition.shortcut !== void 0 && !ANNOTATION_SHORTCUTS.includes(definition.shortcut))
|
|
1456
|
+
fail2(name, `"shortcut" must be one of ${ANNOTATION_SHORTCUTS.join(", ")}`);
|
|
1457
|
+
for (const key of ["resolve", "render"])
|
|
1458
|
+
if (definition[key] !== void 0 && typeof definition[key] !== "function")
|
|
1459
|
+
fail2(name, `"${key}" must be a function`);
|
|
1460
|
+
const out = Object.freeze({
|
|
1461
|
+
name,
|
|
1462
|
+
label: definition.label || name,
|
|
1463
|
+
...definition.description ? { description: definition.description } : {},
|
|
1464
|
+
attributes: Object.freeze(attributes),
|
|
1465
|
+
presets: Object.freeze([...new Set(presets)]),
|
|
1466
|
+
...definition.shortcut ? { shortcut: definition.shortcut } : {},
|
|
1467
|
+
...definition.resolve ? { resolve: definition.resolve } : {},
|
|
1468
|
+
...definition.render ? { render: definition.render } : {}
|
|
1469
|
+
});
|
|
1470
|
+
defined.add(out);
|
|
1471
|
+
return out;
|
|
1472
|
+
};
|
|
1473
|
+
var cleanAnnotationAttributes = (definition, raw) => {
|
|
1474
|
+
const source = raw && typeof raw === "object" ? raw : {};
|
|
1475
|
+
const out = {};
|
|
1476
|
+
for (const [key, field] of Object.entries(definition.attributes)) {
|
|
1477
|
+
const value = Object.prototype.hasOwnProperty.call(source, key) ? source[key] : void 0;
|
|
1478
|
+
let clean2;
|
|
1479
|
+
if (field.type === "text") clean2 = cleanText(value, field.max);
|
|
1480
|
+
else if (field.type === "enum")
|
|
1481
|
+
clean2 = typeof value === "string" && field.values.includes(value) ? value : "";
|
|
1482
|
+
else clean2 = sanitizeUrl(value, { schemes: field.schemes, allowRelative: field.relative });
|
|
1483
|
+
if (clean2) out[key] = clean2;
|
|
1484
|
+
else if (field.required) return null;
|
|
1485
|
+
}
|
|
1486
|
+
return out;
|
|
1487
|
+
};
|
|
1488
|
+
var abbreviationAnnotation = defineInlineAnnotation({
|
|
1489
|
+
name: ABBREVIATION,
|
|
1490
|
+
label: "Abbreviation",
|
|
1491
|
+
description: "Short form with its full form (shown as a tooltip and read by screen readers).",
|
|
1492
|
+
attributes: { title: { type: "text", max: 200, required: true, label: "Full form" } },
|
|
1493
|
+
render: (annotation) => ({ tag: "abbr", attrs: { title: annotation.attrs.title } })
|
|
1494
|
+
});
|
|
1495
|
+
var registry2 = /* @__PURE__ */ new Map();
|
|
1496
|
+
var activeAnnotation = (name) => {
|
|
1497
|
+
if (name === ABBREVIATION) return abbreviationAnnotation;
|
|
1498
|
+
return typeof name === "string" && registry2.has(name) ? registry2.get(name) : null;
|
|
1499
|
+
};
|
|
1500
|
+
var CLASS_TOKEN = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;
|
|
1501
|
+
var RENDER_ATTRIBUTES = /* @__PURE__ */ new Set(["title", "class", "lang", "dir", "href", "datetime", "value", "cite"]);
|
|
1502
|
+
var cleanAnnotationWrapper = (out) => {
|
|
1503
|
+
if (!isObject3(out) || !ANNOTATION_RENDER_TAGS.includes(out.tag)) return null;
|
|
1504
|
+
const attrs = {};
|
|
1505
|
+
for (const [name, raw] of Object.entries(isObject3(out.attrs) ? out.attrs : {})) {
|
|
1506
|
+
if (raw === void 0 || raw === null || raw === false) continue;
|
|
1507
|
+
if (!["string", "number"].includes(typeof raw)) continue;
|
|
1508
|
+
const allowed = RENDER_ATTRIBUTES.has(name) || name === "aria-label" || name.startsWith("data-") && !name.startsWith("data-mex-");
|
|
1509
|
+
if (!allowed || !isSafeAttributeName(name)) continue;
|
|
1510
|
+
const text = String(raw).slice(0, 2e3);
|
|
1511
|
+
if (name === "href" || name === "cite") {
|
|
1512
|
+
if (out.tag !== "a" && name === "href") continue;
|
|
1513
|
+
const url = sanitizeUrl(text);
|
|
1514
|
+
if (url) attrs[name] = url;
|
|
1515
|
+
} else if (name === "class") {
|
|
1516
|
+
const classes2 = text.split(/\s+/).filter((token) => CLASS_TOKEN.test(token));
|
|
1517
|
+
if (classes2.length) attrs.class = classes2.join(" ");
|
|
1518
|
+
} else if (text) attrs[name] = text;
|
|
1519
|
+
}
|
|
1520
|
+
return { tag: out.tag, attrs };
|
|
1521
|
+
};
|
|
1522
|
+
|
|
1523
|
+
// shared/render/inline.mjs
|
|
1524
|
+
var DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
|
|
1525
|
+
"script",
|
|
1526
|
+
"style",
|
|
1527
|
+
"textarea",
|
|
1528
|
+
"title",
|
|
1529
|
+
"xmp",
|
|
1530
|
+
"noscript",
|
|
1531
|
+
"noembed",
|
|
1532
|
+
"noframes",
|
|
1533
|
+
"template",
|
|
1534
|
+
"iframe",
|
|
1535
|
+
"object",
|
|
1536
|
+
"embed",
|
|
1537
|
+
"svg",
|
|
1538
|
+
"math",
|
|
1539
|
+
"select",
|
|
1540
|
+
"option",
|
|
1541
|
+
"plaintext"
|
|
1272
1542
|
]);
|
|
1273
|
-
var
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
mlabeledtr: ["columnalign", "rowalign"],
|
|
1310
|
-
mtd: ["columnalign", "rowalign", "columnspan", "rowspan"],
|
|
1311
|
-
menclose: ["notation"],
|
|
1312
|
-
annotation: ["encoding"]
|
|
1543
|
+
var ALLOWED = new Set(INLINE_TAGS);
|
|
1544
|
+
var VOID = /* @__PURE__ */ new Set(["br"]);
|
|
1545
|
+
var MAX_INPUT = 5e5;
|
|
1546
|
+
var MAX_NODES = 5e4;
|
|
1547
|
+
var MAX_DEPTH = 64;
|
|
1548
|
+
var NAMED_ENTITIES = Object.freeze({
|
|
1549
|
+
amp: "&",
|
|
1550
|
+
lt: "<",
|
|
1551
|
+
gt: ">",
|
|
1552
|
+
quot: '"',
|
|
1553
|
+
apos: "'",
|
|
1554
|
+
nbsp: "\xA0",
|
|
1555
|
+
shy: "\xAD",
|
|
1556
|
+
copy: "\xA9",
|
|
1557
|
+
reg: "\xAE",
|
|
1558
|
+
trade: "\u2122",
|
|
1559
|
+
hellip: "\u2026",
|
|
1560
|
+
mdash: "\u2014",
|
|
1561
|
+
ndash: "\u2013",
|
|
1562
|
+
lsquo: "\u2018",
|
|
1563
|
+
rsquo: "\u2019",
|
|
1564
|
+
ldquo: "\u201C",
|
|
1565
|
+
rdquo: "\u201D",
|
|
1566
|
+
laquo: "\xAB",
|
|
1567
|
+
raquo: "\xBB",
|
|
1568
|
+
euro: "\u20AC",
|
|
1569
|
+
middot: "\xB7",
|
|
1570
|
+
bull: "\u2022",
|
|
1571
|
+
times: "\xD7",
|
|
1572
|
+
deg: "\xB0",
|
|
1573
|
+
tab: " ",
|
|
1574
|
+
newline: "\n",
|
|
1575
|
+
colon: ":",
|
|
1576
|
+
sol: "/",
|
|
1577
|
+
lpar: "(",
|
|
1578
|
+
rpar: ")"
|
|
1313
1579
|
});
|
|
1314
|
-
var
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1580
|
+
var decodeEntities = (text) => String(text).replace(
|
|
1581
|
+
/&(#[xX][0-9a-fA-F]{1,8}|#[0-9]{1,10}|[A-Za-z][A-Za-z0-9]{1,31});?/g,
|
|
1582
|
+
(match, body) => {
|
|
1583
|
+
if (body[0] === "#") {
|
|
1584
|
+
const code = body[1] === "x" || body[1] === "X" ? parseInt(body.slice(2), 16) : parseInt(body.slice(1), 10);
|
|
1585
|
+
if (!Number.isFinite(code) || code <= 0 || code > 1114111 || code >= 55296 && code <= 57343)
|
|
1586
|
+
return "\uFFFD";
|
|
1587
|
+
return String.fromCodePoint(code);
|
|
1588
|
+
}
|
|
1589
|
+
const named = NAMED_ENTITIES[body] ?? NAMED_ENTITIES[body.toLowerCase()];
|
|
1590
|
+
return named === void 0 ? match : named;
|
|
1591
|
+
}
|
|
1592
|
+
);
|
|
1593
|
+
var parseAttributes = (source) => {
|
|
1322
1594
|
const out = {};
|
|
1323
1595
|
const pattern = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
|
|
1324
1596
|
let match;
|
|
1325
1597
|
while (match = pattern.exec(source)) {
|
|
1326
1598
|
const name = match[1].toLowerCase();
|
|
1327
1599
|
if (Object.prototype.hasOwnProperty.call(out, name)) continue;
|
|
1328
|
-
|
|
1600
|
+
const raw = match[2] ?? match[3] ?? match[4] ?? "";
|
|
1601
|
+
out[name] = decodeEntities(raw);
|
|
1329
1602
|
}
|
|
1330
1603
|
return out;
|
|
1331
1604
|
};
|
|
1332
|
-
var
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1605
|
+
var findTagEnd = (html, from) => {
|
|
1606
|
+
let quote = "";
|
|
1607
|
+
for (let i = from; i < html.length; i += 1) {
|
|
1608
|
+
const char = html[i];
|
|
1609
|
+
if (quote) {
|
|
1610
|
+
if (char === quote) quote = "";
|
|
1611
|
+
} else if (char === '"' || char === "'") quote = char;
|
|
1612
|
+
else if (char === ">") return i;
|
|
1613
|
+
}
|
|
1614
|
+
return -1;
|
|
1337
1615
|
};
|
|
1338
|
-
var
|
|
1616
|
+
var cleanAttributes = (tag, attribs, options = {}) => {
|
|
1617
|
+
const allowed = INLINE_ATTRIBUTES[tag] || [];
|
|
1339
1618
|
const out = {};
|
|
1340
|
-
const
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
if (name === "
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
if (
|
|
1355
|
-
|
|
1619
|
+
for (const name of allowed) {
|
|
1620
|
+
if (!Object.prototype.hasOwnProperty.call(attribs, name) || name.startsWith("data-mex-")) continue;
|
|
1621
|
+
const value = attribs[name];
|
|
1622
|
+
if (name === "href") {
|
|
1623
|
+
const url = sanitizeUrl(value);
|
|
1624
|
+
if (url) out.href = url;
|
|
1625
|
+
} else if (name === "target") {
|
|
1626
|
+
const target = sanitizeTarget(value);
|
|
1627
|
+
if (target) out.target = target;
|
|
1628
|
+
} else if (name === "rel") {
|
|
1629
|
+
const rel = String(value).split(/\s+/).filter((token) => /^[a-z-]{1,20}$/.test(token));
|
|
1630
|
+
if (rel.length) out.rel = rel.join(" ");
|
|
1631
|
+
} else if (name === "class") {
|
|
1632
|
+
const classes2 = String(value).split(/\s+/).filter((token) => (INLINE_CLASSES[tag] || []).includes(token));
|
|
1633
|
+
if (classes2.length) out.class = classes2.join(" ");
|
|
1634
|
+
} else {
|
|
1635
|
+
out[name] = String(value).slice(0, 2e3);
|
|
1356
1636
|
}
|
|
1357
|
-
if (!COMMON_ATTRIBUTES.has(name) && !allowed.includes(name)) continue;
|
|
1358
|
-
if (ATTRIBUTE_VALUE.test(value)) out[name] = value;
|
|
1359
1637
|
}
|
|
1360
|
-
if (
|
|
1361
|
-
const color = styleColor(attribs.style, "color");
|
|
1362
|
-
const background = styleColor(attribs.style, "background-color");
|
|
1363
|
-
if (color && !out.mathcolor) out.mathcolor = color;
|
|
1364
|
-
if (background && !out.mathbackground) out.mathbackground = background;
|
|
1365
|
-
}
|
|
1366
|
-
if (tag === "annotation" && out.encoding !== TEX_ENCODING) return null;
|
|
1367
|
-
if (tag === "math" && out.display && out.display !== "block" && out.display !== "inline")
|
|
1368
|
-
delete out.display;
|
|
1638
|
+
if (tag === "a" && !options.inNote) Object.assign(out, cleanInternalLinkAttributes(attribs));
|
|
1369
1639
|
return out;
|
|
1370
1640
|
};
|
|
1371
|
-
var
|
|
1372
|
-
|
|
1641
|
+
var MAX_MARKER_TEXT = 16;
|
|
1642
|
+
var isMathNode = (node) => node.type === "element" && node.tag === "span" && node.attrs[MATH_ATTRIBUTE] === "true";
|
|
1643
|
+
var isFootnoteNode = (node) => node.type === "element" && node.tag === "sup" && typeof node.attrs["data-mex-footnote"] === "string";
|
|
1644
|
+
var isColorNode = (node) => node.type === "element" && node.tag === "span" && typeof node.attrs[COLOR_ATTRIBUTE] === "string";
|
|
1645
|
+
var isHighlightNode = (node) => node.type === "element" && node.tag === "mark" && typeof node.attrs[HIGHLIGHT_ATTRIBUTE] === "string";
|
|
1646
|
+
var isAnnotationNode = (node) => node.type === "element" && node.tag === "span" && typeof node.attrs[ANNOTATION_ATTRIBUTE] === "string";
|
|
1647
|
+
var annotationOf = (node) => {
|
|
1648
|
+
const attrs = {};
|
|
1649
|
+
for (const [name, value] of Object.entries(node.attrs))
|
|
1650
|
+
if (name.startsWith(ANNOTATION_VALUE_PREFIX)) attrs[name.slice(ANNOTATION_VALUE_PREFIX.length)] = value;
|
|
1651
|
+
return { name: node.attrs[ANNOTATION_ATTRIBUTE], attrs };
|
|
1652
|
+
};
|
|
1653
|
+
var annotationAttributes = (name, values) => {
|
|
1654
|
+
const out = { [ANNOTATION_ATTRIBUTE]: name };
|
|
1655
|
+
for (const key of Object.keys(values).sort()) out[`${ANNOTATION_VALUE_PREFIX}${key}`] = values[key];
|
|
1656
|
+
return out;
|
|
1657
|
+
};
|
|
1658
|
+
var finalizeSpecial = (nodes, depth = 0) => {
|
|
1659
|
+
for (const node of nodes) {
|
|
1660
|
+
if (node.type !== "element") continue;
|
|
1661
|
+
if (isMathNode(node)) {
|
|
1662
|
+
const tex = nodesToText(node.children, { raw: true }).replace(/\u200b/g, "").slice(0, MAX_INLINE_TEX);
|
|
1663
|
+
node.children = tex ? [{ type: "text", value: tex }] : [];
|
|
1664
|
+
} else if (isFootnoteNode(node)) {
|
|
1665
|
+
const text = nodesToText(node.children, { raw: true }).slice(0, MAX_MARKER_TEXT);
|
|
1666
|
+
node.children = text ? [{ type: "text", value: text }] : [];
|
|
1667
|
+
} else if (depth < MAX_DEPTH) finalizeSpecial(node.children, depth + 1);
|
|
1668
|
+
}
|
|
1669
|
+
return nodes;
|
|
1670
|
+
};
|
|
1671
|
+
var specialElement = (tag, attribs, options) => {
|
|
1672
|
+
if (tag === "span" && Object.prototype.hasOwnProperty.call(attribs, MATH_ATTRIBUTE)) {
|
|
1673
|
+
if (!/^(?:|true)$/.test(attribs[MATH_ATTRIBUTE])) return null;
|
|
1674
|
+
return { attrs: { [MATH_ATTRIBUTE]: "true" } };
|
|
1675
|
+
}
|
|
1676
|
+
if (tag === "span" && Object.prototype.hasOwnProperty.call(attribs, ANNOTATION_ATTRIBUTE)) {
|
|
1677
|
+
const name = attribs[ANNOTATION_ATTRIBUTE];
|
|
1678
|
+
if (!ANNOTATION_NAME.test(name)) return null;
|
|
1679
|
+
const values = {};
|
|
1680
|
+
for (const [attribute, value] of Object.entries(attribs)) {
|
|
1681
|
+
if (!attribute.startsWith(ANNOTATION_VALUE_PREFIX)) continue;
|
|
1682
|
+
const key = attribute.slice(ANNOTATION_VALUE_PREFIX.length);
|
|
1683
|
+
if (!ANNOTATION_KEY.test(key) || Object.keys(values).length >= ANNOTATION_LIMITS.attributes) continue;
|
|
1684
|
+
const text = String(value).slice(0, ANNOTATION_LIMITS.text);
|
|
1685
|
+
if (text) values[key] = text;
|
|
1686
|
+
}
|
|
1687
|
+
return { attrs: annotationAttributes(name, values) };
|
|
1688
|
+
}
|
|
1689
|
+
if (tag === "span" && Object.prototype.hasOwnProperty.call(attribs, COLOR_ATTRIBUTE)) {
|
|
1690
|
+
return TOKEN_PATTERN.test(attribs[COLOR_ATTRIBUTE]) ? { attrs: { [COLOR_ATTRIBUTE]: attribs[COLOR_ATTRIBUTE] } } : null;
|
|
1691
|
+
}
|
|
1692
|
+
if (tag === "mark" && Object.prototype.hasOwnProperty.call(attribs, HIGHLIGHT_ATTRIBUTE)) {
|
|
1693
|
+
return TOKEN_PATTERN.test(attribs[HIGHLIGHT_ATTRIBUTE]) ? { attrs: { [HIGHLIGHT_ATTRIBUTE]: attribs[HIGHLIGHT_ATTRIBUTE] } } : null;
|
|
1694
|
+
}
|
|
1695
|
+
if (tag === "sup" && !options.inNote) {
|
|
1696
|
+
const id = attribs["data-mex-footnote"];
|
|
1697
|
+
if (typeof id !== "string" || !FOOTNOTE_ID.test(id)) return null;
|
|
1698
|
+
const source = typeof attribs["data-mex-note"] === "string" ? attribs["data-mex-note"] : "";
|
|
1699
|
+
const note = parseInline(source.slice(0, MAX_FOOTNOTE_NOTE), { inNote: true });
|
|
1700
|
+
return { attrs: { "data-mex-footnote": id }, note };
|
|
1701
|
+
}
|
|
1702
|
+
return null;
|
|
1703
|
+
};
|
|
1704
|
+
var parseInline = (input, options = {}) => {
|
|
1705
|
+
const html = typeof input === "string" ? input.slice(0, MAX_INPUT) : "";
|
|
1373
1706
|
const root = { type: "element", tag: "#root", attrs: {}, children: [] };
|
|
1374
1707
|
const stack = [root];
|
|
1375
|
-
let
|
|
1376
|
-
let
|
|
1377
|
-
const
|
|
1708
|
+
let nodes = 0;
|
|
1709
|
+
let text = "";
|
|
1710
|
+
const flush = () => {
|
|
1378
1711
|
if (!text) return;
|
|
1379
1712
|
const parent = stack[stack.length - 1];
|
|
1380
1713
|
const last = parent.children[parent.children.length - 1];
|
|
1381
1714
|
const value = decodeEntities(text);
|
|
1382
1715
|
if (last && last.type === "text") last.value += value;
|
|
1383
|
-
else if (
|
|
1716
|
+
else if (nodes < MAX_NODES) {
|
|
1384
1717
|
parent.children.push({ type: "text", value });
|
|
1385
|
-
|
|
1718
|
+
nodes += 1;
|
|
1386
1719
|
}
|
|
1720
|
+
text = "";
|
|
1387
1721
|
};
|
|
1388
|
-
|
|
1389
|
-
|
|
1722
|
+
let i = 0;
|
|
1723
|
+
while (i < html.length) {
|
|
1724
|
+
const lt = html.indexOf("<", i);
|
|
1390
1725
|
if (lt === -1) {
|
|
1391
|
-
|
|
1726
|
+
text += html.slice(i);
|
|
1392
1727
|
break;
|
|
1393
1728
|
}
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1729
|
+
text += html.slice(i, lt);
|
|
1730
|
+
i = lt;
|
|
1731
|
+
if (html.startsWith("<!--", i)) {
|
|
1732
|
+
const end2 = html.indexOf("-->", i + 4);
|
|
1733
|
+
flush();
|
|
1734
|
+
i = end2 === -1 ? html.length : end2 + 3;
|
|
1398
1735
|
continue;
|
|
1399
1736
|
}
|
|
1400
|
-
if (
|
|
1401
|
-
const end2 =
|
|
1402
|
-
|
|
1737
|
+
if (html.startsWith("<![CDATA[", i)) {
|
|
1738
|
+
const end2 = html.indexOf("]]>", i + 9);
|
|
1739
|
+
flush();
|
|
1740
|
+
i = end2 === -1 ? html.length : end2 + 3;
|
|
1403
1741
|
continue;
|
|
1404
1742
|
}
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
const char = source[j];
|
|
1411
|
-
if (quote) {
|
|
1412
|
-
if (char === quote) quote = "";
|
|
1413
|
-
} else if (char === '"' || char === "'") quote = char;
|
|
1414
|
-
else if (char === ">") {
|
|
1415
|
-
end = j;
|
|
1416
|
-
break;
|
|
1417
|
-
}
|
|
1743
|
+
if (html[i + 1] === "!" || html[i + 1] === "?") {
|
|
1744
|
+
const end2 = html.indexOf(">", i + 2);
|
|
1745
|
+
flush();
|
|
1746
|
+
i = end2 === -1 ? html.length : end2 + 1;
|
|
1747
|
+
continue;
|
|
1418
1748
|
}
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1749
|
+
const closing = html[i + 1] === "/";
|
|
1750
|
+
const nameMatch = /^[A-Za-z][A-Za-z0-9-]{0,40}/.exec(html.slice(i + (closing ? 2 : 1), i + 45));
|
|
1751
|
+
if (!nameMatch) {
|
|
1752
|
+
text += "<";
|
|
1753
|
+
i += 1;
|
|
1422
1754
|
continue;
|
|
1423
1755
|
}
|
|
1756
|
+
const end = findTagEnd(html, i + 1);
|
|
1757
|
+
if (end === -1) {
|
|
1758
|
+
text += html.slice(i);
|
|
1759
|
+
break;
|
|
1760
|
+
}
|
|
1761
|
+
flush();
|
|
1424
1762
|
const tag = nameMatch[0].toLowerCase();
|
|
1425
|
-
const body =
|
|
1763
|
+
const body = html.slice(i + (closing ? 2 : 1) + nameMatch[0].length, end);
|
|
1426
1764
|
i = end + 1;
|
|
1427
1765
|
if (closing) {
|
|
1766
|
+
if (!ALLOWED.has(tag)) continue;
|
|
1428
1767
|
for (let s = stack.length - 1; s > 0; s -= 1) {
|
|
1429
1768
|
if (stack[s].tag === tag) {
|
|
1430
1769
|
stack.length = s;
|
|
@@ -1433,613 +1772,583 @@ var tokenize = (input) => {
|
|
|
1433
1772
|
}
|
|
1434
1773
|
continue;
|
|
1435
1774
|
}
|
|
1436
|
-
if (
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
return root.children;
|
|
1444
|
-
};
|
|
1445
|
-
var clean = (nodes, ctx, depth, inAnnotation) => {
|
|
1446
|
-
const out = [];
|
|
1447
|
-
if (!Array.isArray(nodes) || depth > MAX_DEPTH2) return out;
|
|
1448
|
-
for (const node of nodes) {
|
|
1449
|
-
if (ctx.budget <= 0) break;
|
|
1450
|
-
if (typeof node === "string") {
|
|
1451
|
-
ctx.budget -= 1;
|
|
1452
|
-
if (node) out.push({ type: "text", value: node });
|
|
1453
|
-
continue;
|
|
1454
|
-
}
|
|
1455
|
-
if (!node || typeof node !== "object") continue;
|
|
1456
|
-
ctx.budget -= 1;
|
|
1457
|
-
if (node.type === "text") {
|
|
1458
|
-
if (typeof node.value === "string" && node.value) out.push({ type: "text", value: node.value });
|
|
1775
|
+
if (DROP_WITH_CONTENT.has(tag)) {
|
|
1776
|
+
const selfClosing = /\/\s*$/.test(body);
|
|
1777
|
+
if (selfClosing) continue;
|
|
1778
|
+
const closeIndex = html.slice(i).search(new RegExp(`</${tag}[\\s/>]`, "i"));
|
|
1779
|
+
if (closeIndex === -1) break;
|
|
1780
|
+
const closeEnd = html.indexOf(">", i + closeIndex);
|
|
1781
|
+
i = closeEnd === -1 ? html.length : closeEnd + 1;
|
|
1459
1782
|
continue;
|
|
1460
1783
|
}
|
|
1461
|
-
if (
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
const
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1784
|
+
if (!ALLOWED.has(tag) || nodes >= MAX_NODES) continue;
|
|
1785
|
+
const attribs = parseAttributes(body);
|
|
1786
|
+
const special = specialElement(tag, attribs, options);
|
|
1787
|
+
const element = {
|
|
1788
|
+
type: "element",
|
|
1789
|
+
tag,
|
|
1790
|
+
attrs: special ? special.attrs : cleanAttributes(tag, attribs, options),
|
|
1791
|
+
children: []
|
|
1792
|
+
};
|
|
1793
|
+
if (special && special.note) element.note = special.note;
|
|
1794
|
+
stack[stack.length - 1].children.push(element);
|
|
1795
|
+
nodes += 1;
|
|
1796
|
+
if (!VOID.has(tag) && stack.length < MAX_DEPTH) stack.push(element);
|
|
1468
1797
|
}
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
var cleanMathResult = (result) => {
|
|
1472
|
-
let nodes;
|
|
1473
|
-
if (typeof result === "string") nodes = tokenize(result);
|
|
1474
|
-
else if (Array.isArray(result)) nodes = result;
|
|
1475
|
-
else if (result && typeof result === "object") nodes = [result];
|
|
1476
|
-
else return [];
|
|
1477
|
-
const top = nodes.filter(
|
|
1478
|
-
(node) => node && typeof node === "object" && node.type === "element" && String(node.tag).toLowerCase() === "math"
|
|
1479
|
-
);
|
|
1480
|
-
return clean(top, { budget: MAX_NODES2 }, 0, false);
|
|
1481
|
-
};
|
|
1482
|
-
|
|
1483
|
-
// shared/render/math-notes.mjs
|
|
1484
|
-
var DEFAULT_FOOTNOTES_LABEL = "Footnotes";
|
|
1485
|
-
var DEFAULT_FOOTNOTE_BACK_LABEL = "Back to reference {n}";
|
|
1486
|
-
var DEFAULT_FOOTNOTE_PREFIX = "mex-";
|
|
1487
|
-
var PREFIX = /^[A-Za-z][A-Za-z0-9_-]{0,40}$/;
|
|
1488
|
-
var label = (value, fallback) => {
|
|
1489
|
-
if (typeof value !== "string") return fallback;
|
|
1490
|
-
const clean2 = value.trim();
|
|
1491
|
-
return clean2 && clean2.length <= 80 ? clean2 : fallback;
|
|
1492
|
-
};
|
|
1493
|
-
var footnoteOptions = (options) => {
|
|
1494
|
-
const source = isPlainObject2(options && options.footnotes) ? options.footnotes : {};
|
|
1495
|
-
return {
|
|
1496
|
-
label: label(source.label, DEFAULT_FOOTNOTES_LABEL),
|
|
1497
|
-
backLabel: label(source.backLabel, DEFAULT_FOOTNOTE_BACK_LABEL),
|
|
1498
|
-
prefix: typeof source.prefix === "string" && PREFIX.test(source.prefix) ? source.prefix : DEFAULT_FOOTNOTE_PREFIX
|
|
1499
|
-
};
|
|
1500
|
-
};
|
|
1501
|
-
var createFootnoteNumbers = () => {
|
|
1502
|
-
const used = /* @__PURE__ */ new Map();
|
|
1503
|
-
let count = 0;
|
|
1504
|
-
return {
|
|
1505
|
-
add(id) {
|
|
1506
|
-
const seen = (used.get(id) || 0) + 1;
|
|
1507
|
-
used.set(id, seen);
|
|
1508
|
-
count += 1;
|
|
1509
|
-
return { n: count, anchor: seen === 1 ? id : `${id}-${seen}` };
|
|
1510
|
-
}
|
|
1511
|
-
};
|
|
1798
|
+
flush();
|
|
1799
|
+
return finalizeSpecial(root.children);
|
|
1512
1800
|
};
|
|
1513
|
-
var
|
|
1514
|
-
if (
|
|
1801
|
+
var resolveLinkAttributes = (attrs, resolver) => {
|
|
1802
|
+
if (typeof resolver !== "function" || !attrs["data-mex-uid"] || !attrs["data-mex-document-id"])
|
|
1803
|
+
return attrs;
|
|
1515
1804
|
let result;
|
|
1516
1805
|
try {
|
|
1517
|
-
result =
|
|
1806
|
+
result = resolver({
|
|
1807
|
+
uid: attrs["data-mex-uid"],
|
|
1808
|
+
documentId: attrs["data-mex-document-id"],
|
|
1809
|
+
locale: attrs["data-mex-locale"] || null,
|
|
1810
|
+
href: attrs.href || null,
|
|
1811
|
+
...isMentionLink(attrs) ? { mention: true } : {}
|
|
1812
|
+
});
|
|
1518
1813
|
} catch {
|
|
1519
|
-
|
|
1814
|
+
result = void 0;
|
|
1520
1815
|
}
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
"data-mex-math": kind.display ? "display" : "inline"
|
|
1528
|
-
};
|
|
1529
|
-
const children = math.length ? math : kind.display ? `\\[${tex}\\]` : `\\(${tex}\\)`;
|
|
1530
|
-
return el(kind.block ? "div" : "span", attrs, children);
|
|
1816
|
+
if (result === false) return null;
|
|
1817
|
+
if (typeof result === "string") {
|
|
1818
|
+
const url = sanitizeUrl(result);
|
|
1819
|
+
if (url) return { ...attrs, href: url };
|
|
1820
|
+
}
|
|
1821
|
+
return attrs;
|
|
1531
1822
|
};
|
|
1532
|
-
var
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
const labelId = `${prefix}footnotes-label`;
|
|
1537
|
-
return {
|
|
1538
|
-
marker(node) {
|
|
1539
|
-
const { n, anchor } = numbers.add(node.attrs["data-mex-footnote"]);
|
|
1540
|
-
items.push({ n, anchor, note: node.note || [] });
|
|
1541
|
-
return el(
|
|
1542
|
-
"sup",
|
|
1543
|
-
{ class: "mex-footnote-ref" },
|
|
1544
|
-
el(
|
|
1545
|
-
"a",
|
|
1546
|
-
{
|
|
1547
|
-
href: `#${prefix}fn-${anchor}`,
|
|
1548
|
-
id: `${prefix}fnref-${anchor}`,
|
|
1549
|
-
"aria-describedby": labelId
|
|
1550
|
-
},
|
|
1551
|
-
String(n)
|
|
1552
|
-
)
|
|
1553
|
-
);
|
|
1554
|
-
},
|
|
1555
|
-
section() {
|
|
1556
|
-
if (!items.length) return null;
|
|
1557
|
-
return el("section", { class: "mex-footnotes", "aria-labelledby": labelId }, [
|
|
1558
|
-
el("h2", { id: labelId, class: "mex-footnotes-label" }, listLabel),
|
|
1559
|
-
el(
|
|
1560
|
-
"ol",
|
|
1561
|
-
{ class: "mex-footnotes-list" },
|
|
1562
|
-
items.map(
|
|
1563
|
-
(item) => el("li", { id: `${prefix}fn-${item.anchor}`, class: "mex-footnote" }, [
|
|
1564
|
-
renderNote(item.note),
|
|
1565
|
-
" ",
|
|
1566
|
-
el(
|
|
1567
|
-
"a",
|
|
1568
|
-
{
|
|
1569
|
-
href: `#${prefix}fnref-${item.anchor}`,
|
|
1570
|
-
class: "mex-footnote-back",
|
|
1571
|
-
"aria-label": backLabel.replace(/\{n\}/g, String(item.n))
|
|
1572
|
-
},
|
|
1573
|
-
"\u21A9"
|
|
1574
|
-
)
|
|
1575
|
-
])
|
|
1576
|
-
)
|
|
1577
|
-
)
|
|
1578
|
-
]);
|
|
1579
|
-
}
|
|
1580
|
-
};
|
|
1581
|
-
};
|
|
1582
|
-
|
|
1583
|
-
// shared/blocks/define.mjs
|
|
1584
|
-
var BLOCK_FIELD_TYPES = Object.freeze([
|
|
1585
|
-
"text",
|
|
1586
|
-
"inline",
|
|
1587
|
-
"url",
|
|
1588
|
-
"enum",
|
|
1589
|
-
"number",
|
|
1590
|
-
"boolean",
|
|
1591
|
-
"array",
|
|
1592
|
-
"object"
|
|
1593
|
-
]);
|
|
1594
|
-
var BLOCK_LIMITS = Object.freeze({
|
|
1595
|
-
/** Fields per object (also the schema root). */
|
|
1596
|
-
maxFields: 50,
|
|
1597
|
-
/** Nesting of arrays and objects below the root. */
|
|
1598
|
-
maxDepth: 4,
|
|
1599
|
-
/** Largest `max` of a text or inline field. */
|
|
1600
|
-
maxText: 1e5,
|
|
1601
|
-
/** Default `max` of a text field. */
|
|
1602
|
-
defaultText: 1e3,
|
|
1603
|
-
/** Default `max` of an inline HTML field. */
|
|
1604
|
-
defaultInline: 1e4,
|
|
1605
|
-
/** Largest `max` of an array field. */
|
|
1606
|
-
maxItems: 500,
|
|
1607
|
-
/** Default `max` of an array field. */
|
|
1608
|
-
defaultItems: 50,
|
|
1609
|
-
/** Values of an enum field. */
|
|
1610
|
-
maxEnumValues: 100,
|
|
1611
|
-
/** Values cleaned per block; later array items are dropped. */
|
|
1612
|
-
maxValues: 2e4,
|
|
1613
|
-
/** Length of a URL value. */
|
|
1614
|
-
maxUrl: 2048
|
|
1615
|
-
});
|
|
1616
|
-
var BLOCK_PRESETS = Object.freeze(["article", "basic", "minimal"]);
|
|
1617
|
-
var RESERVED_BLOCK_NAMES = Object.freeze([
|
|
1618
|
-
"paragraph",
|
|
1619
|
-
"header",
|
|
1620
|
-
"list",
|
|
1621
|
-
"checklist",
|
|
1622
|
-
"quote",
|
|
1623
|
-
"warning",
|
|
1624
|
-
"alert",
|
|
1625
|
-
"toggle",
|
|
1626
|
-
"code",
|
|
1627
|
-
"codeFlask",
|
|
1628
|
-
"delimiter",
|
|
1629
|
-
"toc",
|
|
1630
|
-
"synced",
|
|
1631
|
-
"table",
|
|
1632
|
-
"embed",
|
|
1633
|
-
"raw",
|
|
1634
|
-
"image",
|
|
1635
|
-
"simpleImage",
|
|
1636
|
-
"gallery",
|
|
1637
|
-
"video",
|
|
1638
|
-
"audio",
|
|
1639
|
-
"linkTool",
|
|
1640
|
-
"attaches",
|
|
1641
|
-
"personality",
|
|
1642
|
-
"button",
|
|
1643
|
-
"mediaLib",
|
|
1644
|
-
"embeddedEntry",
|
|
1645
|
-
"bold",
|
|
1646
|
-
"italic",
|
|
1647
|
-
"hyperlink",
|
|
1648
|
-
"mention",
|
|
1649
|
-
"marker",
|
|
1650
|
-
"underline",
|
|
1651
|
-
"strikethrough",
|
|
1652
|
-
"inlineCode",
|
|
1653
|
-
"tooltip",
|
|
1654
|
-
"aiAssistant",
|
|
1655
|
-
"alignmentTune",
|
|
1656
|
-
"textVariant",
|
|
1657
|
-
"indentTune"
|
|
1658
|
-
]);
|
|
1659
|
-
var SDK_COMPATIBLE_NAMES = Object.freeze(["math"]);
|
|
1660
|
-
var RESERVED = new Set(RESERVED_BLOCK_NAMES.map((name) => name.toLowerCase()));
|
|
1661
|
-
var BLOCK_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{1,49}$/;
|
|
1662
|
-
var KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
|
1663
|
-
var FORBIDDEN_KEYS2 = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
1664
|
-
var DEFINITION_KEYS = /* @__PURE__ */ new Set([
|
|
1665
|
-
"name",
|
|
1666
|
-
"version",
|
|
1823
|
+
var ATTRIBUTE_ORDER = [
|
|
1824
|
+
"href",
|
|
1825
|
+
"target",
|
|
1826
|
+
"rel",
|
|
1667
1827
|
"title",
|
|
1668
|
-
"
|
|
1669
|
-
"
|
|
1670
|
-
"
|
|
1671
|
-
"
|
|
1672
|
-
"
|
|
1673
|
-
"
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1828
|
+
"class",
|
|
1829
|
+
"data-tooltip",
|
|
1830
|
+
"data-mex-uid",
|
|
1831
|
+
"data-mex-document-id",
|
|
1832
|
+
"data-mex-locale",
|
|
1833
|
+
"data-mex-mention",
|
|
1834
|
+
MATH_ATTRIBUTE,
|
|
1835
|
+
"data-mex-footnote",
|
|
1836
|
+
"data-mex-note"
|
|
1837
|
+
];
|
|
1838
|
+
var RENDER_STATE = /* @__PURE__ */ Symbol.for("magic-editor-x.render-state");
|
|
1839
|
+
var storedNote = (note) => serializeNodes(inlineNodesToRender(note || [], { storage: true }));
|
|
1840
|
+
var MENTION_CLASS = "mex-mention";
|
|
1841
|
+
var inlineNodesToRender = (nodes, options = {}) => {
|
|
1842
|
+
const out = [];
|
|
1843
|
+
const state = options[RENDER_STATE];
|
|
1844
|
+
for (const node of nodes) {
|
|
1845
|
+
if (node.type === "text") {
|
|
1846
|
+
out.push({ type: "text", value: node.value });
|
|
1847
|
+
continue;
|
|
1848
|
+
}
|
|
1849
|
+
if (node.tag === "br") {
|
|
1850
|
+
out.push({ type: "element", tag: "br", attrs: {}, children: [] });
|
|
1851
|
+
continue;
|
|
1852
|
+
}
|
|
1853
|
+
if (isMathNode(node)) {
|
|
1854
|
+
const tex = nodesToText(node.children);
|
|
1855
|
+
if (state && !options.storage) {
|
|
1856
|
+
if (tex.trim()) out.push(state.math(tex, false));
|
|
1857
|
+
continue;
|
|
1858
|
+
}
|
|
1859
|
+
out.push({
|
|
1860
|
+
type: "element",
|
|
1861
|
+
tag: "span",
|
|
1862
|
+
attrs: { [MATH_ATTRIBUTE]: "true" },
|
|
1863
|
+
children: tex ? [{ type: "text", value: tex }] : []
|
|
1864
|
+
});
|
|
1865
|
+
continue;
|
|
1866
|
+
}
|
|
1867
|
+
if (isFootnoteNode(node)) {
|
|
1868
|
+
if (state && !options.storage) {
|
|
1869
|
+
out.push(state.footnote(node));
|
|
1870
|
+
continue;
|
|
1871
|
+
}
|
|
1872
|
+
const attrs2 = { "data-mex-footnote": node.attrs["data-mex-footnote"] };
|
|
1873
|
+
const note = storedNote(node.note);
|
|
1874
|
+
if (note) attrs2["data-mex-note"] = note;
|
|
1875
|
+
out.push({ type: "element", tag: "sup", attrs: attrs2, children: inlineNodesToRender(node.children, options) });
|
|
1876
|
+
continue;
|
|
1877
|
+
}
|
|
1878
|
+
if (isColorNode(node) || isHighlightNode(node)) {
|
|
1879
|
+
const color = node.tag === "span";
|
|
1880
|
+
const name = color ? COLOR_ATTRIBUTE : HIGHLIGHT_ATTRIBUTE;
|
|
1881
|
+
const token = node.attrs[name];
|
|
1882
|
+
out.push({
|
|
1883
|
+
type: "element",
|
|
1884
|
+
tag: node.tag,
|
|
1885
|
+
attrs: options.storage ? { [name]: token } : { class: color ? colorClass(token) : highlightClass(token), [name]: token },
|
|
1886
|
+
children: inlineNodesToRender(node.children, options)
|
|
1887
|
+
});
|
|
1888
|
+
continue;
|
|
1889
|
+
}
|
|
1890
|
+
if (isAnnotationNode(node)) {
|
|
1891
|
+
const children = inlineNodesToRender(node.children, options);
|
|
1892
|
+
if (options.storage) out.push({ type: "element", tag: "span", attrs: { ...node.attrs }, children });
|
|
1893
|
+
else out.push(...renderAnnotation(node, children, options));
|
|
1894
|
+
continue;
|
|
1895
|
+
}
|
|
1896
|
+
let attrs = node.attrs;
|
|
1897
|
+
if (node.tag === "a") {
|
|
1898
|
+
attrs = resolveLinkAttributes(attrs, options.links);
|
|
1899
|
+
if (!attrs || !attrs.href) {
|
|
1900
|
+
out.push(...inlineNodesToRender(node.children, options));
|
|
1901
|
+
continue;
|
|
1902
|
+
}
|
|
1903
|
+
if (attrs.target === "_blank") {
|
|
1904
|
+
const rel = new Set(
|
|
1905
|
+
String(attrs.rel || "").split(/\s+/).filter(Boolean)
|
|
1906
|
+
);
|
|
1907
|
+
rel.add("noopener");
|
|
1908
|
+
rel.add("noreferrer");
|
|
1909
|
+
attrs = { ...attrs, rel: Array.from(rel).sort().join(" ") };
|
|
1910
|
+
}
|
|
1911
|
+
if (!options.storage && isMentionLink(attrs)) attrs = { ...attrs, class: MENTION_CLASS };
|
|
1912
|
+
}
|
|
1913
|
+
const ordered = {};
|
|
1914
|
+
for (const name of ATTRIBUTE_ORDER) {
|
|
1915
|
+
if (attrs[name] !== void 0 && attrs[name] !== "") ordered[name] = String(attrs[name]);
|
|
1916
|
+
}
|
|
1917
|
+
out.push({
|
|
1918
|
+
type: "element",
|
|
1919
|
+
tag: node.tag,
|
|
1920
|
+
attrs: ordered,
|
|
1921
|
+
children: inlineNodesToRender(node.children, options)
|
|
1922
|
+
});
|
|
1695
1923
|
}
|
|
1924
|
+
return out;
|
|
1696
1925
|
};
|
|
1697
|
-
var
|
|
1698
|
-
var
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1926
|
+
var annotationLists = /* @__PURE__ */ new WeakMap();
|
|
1927
|
+
var annotationDefinition = (name, options) => {
|
|
1928
|
+
const list = options.annotations;
|
|
1929
|
+
if (Array.isArray(list)) {
|
|
1930
|
+
if (!annotationLists.has(list)) {
|
|
1931
|
+
const map = /* @__PURE__ */ new Map();
|
|
1932
|
+
for (const item of list.slice(0, ANNOTATION_LIMITS.registered))
|
|
1933
|
+
if (item && typeof item === "object" && typeof item.name === "string" && item.attributes)
|
|
1934
|
+
map.set(item.name, item);
|
|
1935
|
+
annotationLists.set(list, map);
|
|
1936
|
+
}
|
|
1937
|
+
const found = annotationLists.get(list).get(name);
|
|
1938
|
+
if (found) return found;
|
|
1939
|
+
}
|
|
1940
|
+
return activeAnnotation(name);
|
|
1941
|
+
};
|
|
1942
|
+
var resolvedValue = (options, annotation) => {
|
|
1943
|
+
if (typeof options.resolveAnnotation !== "function") return void 0;
|
|
1944
|
+
let value;
|
|
1945
|
+
try {
|
|
1946
|
+
value = options.resolveAnnotation(annotation);
|
|
1947
|
+
} catch {
|
|
1948
|
+
return void 0;
|
|
1949
|
+
}
|
|
1950
|
+
if (typeof value === "string") return value.slice(0, 2e3);
|
|
1951
|
+
if (value && typeof value === "object" && !Array.isArray(value)) return value;
|
|
1952
|
+
return void 0;
|
|
1953
|
+
};
|
|
1954
|
+
var renderAnnotation = (node, children, options) => {
|
|
1955
|
+
const { name, attrs } = annotationOf(node);
|
|
1956
|
+
const definition = annotationDefinition(name, options);
|
|
1957
|
+
const values = definition ? cleanAnnotationAttributes(definition, attrs) : attrs;
|
|
1958
|
+
if (!values) return children;
|
|
1959
|
+
if (definition && typeof definition.render === "function") {
|
|
1960
|
+
const text = nodesToText(node.children);
|
|
1961
|
+
let out;
|
|
1962
|
+
try {
|
|
1963
|
+
out = definition.render({
|
|
1964
|
+
name,
|
|
1965
|
+
attrs: { ...values },
|
|
1966
|
+
text,
|
|
1967
|
+
resolved: resolvedValue(options, { name, attrs: { ...values }, text })
|
|
1968
|
+
});
|
|
1969
|
+
} catch {
|
|
1970
|
+
out = void 0;
|
|
1971
|
+
}
|
|
1972
|
+
if (out === false) return children;
|
|
1973
|
+
const wrapper = cleanAnnotationWrapper(out);
|
|
1974
|
+
if (wrapper) return [{ type: "element", tag: wrapper.tag, attrs: wrapper.attrs, children }];
|
|
1719
1975
|
}
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
"max"
|
|
1730
|
-
);
|
|
1731
|
-
if (input.default !== void 0 && typeof input.default !== "string")
|
|
1732
|
-
fail(where, '"default" must be a string');
|
|
1733
|
-
out.default = (input.default || "").slice(0, out.max);
|
|
1734
|
-
if (type === "text") {
|
|
1735
|
-
if (input.multiline !== void 0 && typeof input.multiline !== "boolean")
|
|
1736
|
-
fail(where, '"multiline" must be a boolean');
|
|
1737
|
-
out.multiline = input.multiline === true;
|
|
1738
|
-
}
|
|
1739
|
-
break;
|
|
1976
|
+
return [
|
|
1977
|
+
{
|
|
1978
|
+
type: "element",
|
|
1979
|
+
tag: "span",
|
|
1980
|
+
attrs: {
|
|
1981
|
+
class: `mex-annotation mex-annotation-${name}`,
|
|
1982
|
+
...annotationAttributes(name, definition ? values : {})
|
|
1983
|
+
},
|
|
1984
|
+
children
|
|
1740
1985
|
}
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1986
|
+
];
|
|
1987
|
+
};
|
|
1988
|
+
var inlineToNodes = (html, options) => inlineNodesToRender(parseInline(html), options);
|
|
1989
|
+
var nodesToHtml = (nodes, options = {}) => serializeNodes(inlineNodesToRender(nodes, options));
|
|
1990
|
+
var nodesToText = (nodes, options = {}) => nodes.map((node) => {
|
|
1991
|
+
if (node.type === "text") return node.value;
|
|
1992
|
+
if (node.tag === "br") return "\n";
|
|
1993
|
+
if (!options.raw && isFootnoteNode(node))
|
|
1994
|
+
return typeof options.footnote === "function" ? options.footnote(node) : "";
|
|
1995
|
+
return nodesToText(node.children, options);
|
|
1996
|
+
}).join("");
|
|
1997
|
+
var inlineToHtml = (html, options) => nodesToHtml(parseInline(html), options);
|
|
1998
|
+
var inlineToText = (html, options) => nodesToText(parseInline(html), options).replace(/\u00a0/g, " ");
|
|
1999
|
+
|
|
2000
|
+
// shared/render/mathml.mjs
|
|
2001
|
+
var MATHML_TAGS = Object.freeze([
|
|
2002
|
+
"math",
|
|
2003
|
+
"semantics",
|
|
2004
|
+
"annotation",
|
|
2005
|
+
"mrow",
|
|
2006
|
+
"mi",
|
|
2007
|
+
"mn",
|
|
2008
|
+
"mo",
|
|
2009
|
+
"ms",
|
|
2010
|
+
"mtext",
|
|
2011
|
+
"mspace",
|
|
2012
|
+
"msub",
|
|
2013
|
+
"msup",
|
|
2014
|
+
"msubsup",
|
|
2015
|
+
"munder",
|
|
2016
|
+
"mover",
|
|
2017
|
+
"munderover",
|
|
2018
|
+
"mfrac",
|
|
2019
|
+
"msqrt",
|
|
2020
|
+
"mroot",
|
|
2021
|
+
"mstyle",
|
|
2022
|
+
"merror",
|
|
2023
|
+
"mpadded",
|
|
2024
|
+
"mphantom",
|
|
2025
|
+
"mtable",
|
|
2026
|
+
"mtr",
|
|
2027
|
+
"mtd",
|
|
2028
|
+
"mlabeledtr",
|
|
2029
|
+
"mmultiscripts",
|
|
2030
|
+
"mprescripts",
|
|
2031
|
+
"none",
|
|
2032
|
+
"menclose"
|
|
2033
|
+
]);
|
|
2034
|
+
var TAGS = new Set(MATHML_TAGS);
|
|
2035
|
+
var COMMON_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
2036
|
+
"dir",
|
|
2037
|
+
"displaystyle",
|
|
2038
|
+
"scriptlevel",
|
|
2039
|
+
"mathvariant",
|
|
2040
|
+
"mathsize",
|
|
2041
|
+
"mathcolor",
|
|
2042
|
+
"mathbackground"
|
|
2043
|
+
]);
|
|
2044
|
+
var ELEMENT_ATTRIBUTES = Object.freeze({
|
|
2045
|
+
math: ["display"],
|
|
2046
|
+
mo: [
|
|
2047
|
+
"form",
|
|
2048
|
+
"fence",
|
|
2049
|
+
"separator",
|
|
2050
|
+
"stretchy",
|
|
2051
|
+
"symmetric",
|
|
2052
|
+
"largeop",
|
|
2053
|
+
"movablelimits",
|
|
2054
|
+
"lspace",
|
|
2055
|
+
"rspace",
|
|
2056
|
+
"minsize",
|
|
2057
|
+
"maxsize",
|
|
2058
|
+
"accent"
|
|
2059
|
+
],
|
|
2060
|
+
mspace: ["width", "height", "depth"],
|
|
2061
|
+
mpadded: ["width", "height", "depth", "lspace", "voffset"],
|
|
2062
|
+
mfrac: ["linethickness"],
|
|
2063
|
+
mover: ["accent"],
|
|
2064
|
+
munder: ["accentunder"],
|
|
2065
|
+
munderover: ["accent", "accentunder"],
|
|
2066
|
+
mtable: [
|
|
2067
|
+
"columnalign",
|
|
2068
|
+
"rowalign",
|
|
2069
|
+
"columnspacing",
|
|
2070
|
+
"rowspacing",
|
|
2071
|
+
"columnlines",
|
|
2072
|
+
"rowlines",
|
|
2073
|
+
"frame",
|
|
2074
|
+
"framespacing",
|
|
2075
|
+
"equalrows",
|
|
2076
|
+
"equalcolumns",
|
|
2077
|
+
"side"
|
|
2078
|
+
],
|
|
2079
|
+
mtr: ["columnalign", "rowalign"],
|
|
2080
|
+
mlabeledtr: ["columnalign", "rowalign"],
|
|
2081
|
+
mtd: ["columnalign", "rowalign", "columnspan", "rowspan"],
|
|
2082
|
+
menclose: ["notation"],
|
|
2083
|
+
annotation: ["encoding"]
|
|
2084
|
+
});
|
|
2085
|
+
var ATTRIBUTE_VALUE = /^[A-Za-z0-9 .%#+-]{0,100}$/;
|
|
2086
|
+
var COLOR_VALUE = /^(?:#[0-9A-Fa-f]{3,8}|[A-Za-z]{1,30})$/;
|
|
2087
|
+
var CLASS_TOKEN2 = /^tml-[a-z0-9-]{1,40}$/;
|
|
2088
|
+
var TEX_ENCODING = "application/x-tex";
|
|
2089
|
+
var MAX_INPUT2 = 2e5;
|
|
2090
|
+
var MAX_NODES2 = 2e4;
|
|
2091
|
+
var MAX_DEPTH2 = 64;
|
|
2092
|
+
var parseAttributes2 = (source) => {
|
|
2093
|
+
const out = {};
|
|
2094
|
+
const pattern = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
|
|
2095
|
+
let match;
|
|
2096
|
+
while (match = pattern.exec(source)) {
|
|
2097
|
+
const name = match[1].toLowerCase();
|
|
2098
|
+
if (Object.prototype.hasOwnProperty.call(out, name)) continue;
|
|
2099
|
+
out[name] = decodeEntities(match[2] ?? match[3] ?? match[4] ?? "");
|
|
2100
|
+
}
|
|
2101
|
+
return out;
|
|
2102
|
+
};
|
|
2103
|
+
var styleColor = (style, property) => {
|
|
2104
|
+
const pattern = property === "color" ? /(?:^|;)\s*color\s*:\s*([^;]+)/i : /background-color\s*:\s*([^;]+)/i;
|
|
2105
|
+
const match = pattern.exec(style);
|
|
2106
|
+
const value = match ? match[1].trim() : "";
|
|
2107
|
+
return COLOR_VALUE.test(value) ? value : "";
|
|
2108
|
+
};
|
|
2109
|
+
var cleanAttributes2 = (tag, attribs) => {
|
|
2110
|
+
const out = {};
|
|
2111
|
+
const allowed = ELEMENT_ATTRIBUTES[tag] || [];
|
|
2112
|
+
for (const [name, raw] of Object.entries(attribs)) {
|
|
2113
|
+
if (typeof raw !== "string" && typeof raw !== "number" && raw !== true) continue;
|
|
2114
|
+
const value = raw === true ? "true" : String(raw);
|
|
2115
|
+
if (name === "class") {
|
|
2116
|
+
const classes2 = value.split(/\s+/).filter((token) => CLASS_TOKEN2.test(token));
|
|
2117
|
+
if (classes2.length) out.class = classes2.slice(0, 8).join(" ");
|
|
2118
|
+
continue;
|
|
1750
2119
|
}
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
fail(
|
|
1755
|
-
where,
|
|
1756
|
-
`"values" must be 1 to ${BLOCK_LIMITS.maxEnumValues} distinct strings (1-100 characters)`
|
|
1757
|
-
);
|
|
1758
|
-
out.values = Object.freeze([...values]);
|
|
1759
|
-
if (input.default !== void 0 && !values.includes(input.default))
|
|
1760
|
-
fail(where, '"default" must be one of "values"');
|
|
1761
|
-
out.default = input.default === void 0 ? values[0] : input.default;
|
|
1762
|
-
break;
|
|
2120
|
+
if (name === "encoding") {
|
|
2121
|
+
if (tag === "annotation" && value === TEX_ENCODING) out.encoding = value;
|
|
2122
|
+
continue;
|
|
1763
2123
|
}
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
fail(where, `"${key}" must be a finite number`);
|
|
1768
|
-
if (input.integer !== void 0 && typeof input.integer !== "boolean")
|
|
1769
|
-
fail(where, '"integer" must be a boolean');
|
|
1770
|
-
out.integer = input.integer === true;
|
|
1771
|
-
out.min = input.min === void 0 ? -Number.MAX_SAFE_INTEGER : input.min;
|
|
1772
|
-
out.max = input.max === void 0 ? Number.MAX_SAFE_INTEGER : input.max;
|
|
1773
|
-
if (out.min > out.max) fail(where, '"min" must not be greater than "max"');
|
|
1774
|
-
if (input.default !== void 0) {
|
|
1775
|
-
if (input.default < out.min || input.default > out.max || out.integer && !Number.isInteger(input.default))
|
|
1776
|
-
fail(where, '"default" must be a valid value of the field');
|
|
1777
|
-
out.default = input.default;
|
|
1778
|
-
}
|
|
1779
|
-
break;
|
|
2124
|
+
if (name === "mathcolor" || name === "mathbackground") {
|
|
2125
|
+
if (COLOR_VALUE.test(value)) out[name] = value;
|
|
2126
|
+
continue;
|
|
1780
2127
|
}
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
fail(where, '"default" must be a boolean');
|
|
1784
|
-
out.default = input.default === true;
|
|
1785
|
-
break;
|
|
1786
|
-
case "array":
|
|
1787
|
-
if (depth >= BLOCK_LIMITS.maxDepth) fail(where, `fields nest at most ${BLOCK_LIMITS.maxDepth} levels`);
|
|
1788
|
-
out.max = boundedInt(input.max, 1, BLOCK_LIMITS.maxItems, BLOCK_LIMITS.defaultItems, where, "max");
|
|
1789
|
-
out.items = normalizeField(input.items, `${where}[]`, depth + 1);
|
|
1790
|
-
break;
|
|
1791
|
-
case "object":
|
|
1792
|
-
if (depth >= BLOCK_LIMITS.maxDepth) fail(where, `fields nest at most ${BLOCK_LIMITS.maxDepth} levels`);
|
|
1793
|
-
out.fields = normalizeFields(input.fields, where, depth + 1);
|
|
1794
|
-
break;
|
|
1795
|
-
default:
|
|
1796
|
-
break;
|
|
2128
|
+
if (!COMMON_ATTRIBUTES.has(name) && !allowed.includes(name)) continue;
|
|
2129
|
+
if (ATTRIBUTE_VALUE.test(value)) out[name] = value;
|
|
1797
2130
|
}
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
if (keys.length < 1 || keys.length > BLOCK_LIMITS.maxFields)
|
|
1804
|
-
fail(where, `an object needs 1 to ${BLOCK_LIMITS.maxFields} fields`);
|
|
1805
|
-
const out = /* @__PURE__ */ Object.create(null);
|
|
1806
|
-
for (const key of keys) {
|
|
1807
|
-
if (!KEY_PATTERN.test(key) || FORBIDDEN_KEYS2.has(key))
|
|
1808
|
-
fail(where, `field name ${JSON.stringify(key)} must match ${KEY_PATTERN}`);
|
|
1809
|
-
out[key] = normalizeField(input[key], `${where}.${key}`, depth);
|
|
2131
|
+
if (typeof attribs.style === "string") {
|
|
2132
|
+
const color = styleColor(attribs.style, "color");
|
|
2133
|
+
const background = styleColor(attribs.style, "background-color");
|
|
2134
|
+
if (color && !out.mathcolor) out.mathcolor = color;
|
|
2135
|
+
if (background && !out.mathbackground) out.mathbackground = background;
|
|
1810
2136
|
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
return `the name must match ${BLOCK_NAME_PATTERN}`;
|
|
1816
|
-
if (RESERVED.has(name.toLowerCase())) return `"${name}" is a built-in tool name`;
|
|
1817
|
-
return null;
|
|
2137
|
+
if (tag === "annotation" && out.encoding !== TEX_ENCODING) return null;
|
|
2138
|
+
if (tag === "math" && out.display && out.display !== "block" && out.display !== "inline")
|
|
2139
|
+
delete out.display;
|
|
2140
|
+
return out;
|
|
1818
2141
|
};
|
|
1819
|
-
var
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
const
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
const
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
);
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
2142
|
+
var tokenize = (input) => {
|
|
2143
|
+
const source = input.slice(0, MAX_INPUT2);
|
|
2144
|
+
const root = { type: "element", tag: "#root", attrs: {}, children: [] };
|
|
2145
|
+
const stack = [root];
|
|
2146
|
+
let count = 0;
|
|
2147
|
+
let i = 0;
|
|
2148
|
+
const pushText = (text) => {
|
|
2149
|
+
if (!text) return;
|
|
2150
|
+
const parent = stack[stack.length - 1];
|
|
2151
|
+
const last = parent.children[parent.children.length - 1];
|
|
2152
|
+
const value = decodeEntities(text);
|
|
2153
|
+
if (last && last.type === "text") last.value += value;
|
|
2154
|
+
else if (count < MAX_NODES2) {
|
|
2155
|
+
parent.children.push({ type: "text", value });
|
|
2156
|
+
count += 1;
|
|
2157
|
+
}
|
|
1834
2158
|
};
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
if (
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
return typeof value === "string" ? sanitizeUrl(value.slice(0, BLOCK_LIMITS.maxUrl), {
|
|
1865
|
-
schemes: field.schemes,
|
|
1866
|
-
allowRelative: field.relative
|
|
1867
|
-
}) : "";
|
|
1868
|
-
case "enum":
|
|
1869
|
-
return typeof value === "string" && field.values.includes(value) ? value : field.default;
|
|
1870
|
-
case "number":
|
|
1871
|
-
return typeof value === "number" && Number.isFinite(value) && value >= field.min && value <= field.max && (!field.integer || Number.isInteger(value)) ? value : field.default;
|
|
1872
|
-
case "boolean":
|
|
1873
|
-
return typeof value === "boolean" ? value : field.default;
|
|
1874
|
-
case "array": {
|
|
1875
|
-
const out = [];
|
|
1876
|
-
if (!Array.isArray(value)) return out;
|
|
1877
|
-
for (const item of value) {
|
|
1878
|
-
if (out.length >= field.max || budget.left <= 0) break;
|
|
1879
|
-
if (!matchesType(field.items, item)) continue;
|
|
1880
|
-
const clean2 = cleanValue(field.items, item, inline, budget);
|
|
1881
|
-
if (clean2 !== void 0) out.push(clean2);
|
|
2159
|
+
while (i < source.length) {
|
|
2160
|
+
const lt = source.indexOf("<", i);
|
|
2161
|
+
if (lt === -1) {
|
|
2162
|
+
pushText(source.slice(i));
|
|
2163
|
+
break;
|
|
2164
|
+
}
|
|
2165
|
+
pushText(source.slice(i, lt));
|
|
2166
|
+
if (source.startsWith("<!--", lt)) {
|
|
2167
|
+
const end2 = source.indexOf("-->", lt + 4);
|
|
2168
|
+
i = end2 === -1 ? source.length : end2 + 3;
|
|
2169
|
+
continue;
|
|
2170
|
+
}
|
|
2171
|
+
if (source[lt + 1] === "!" || source[lt + 1] === "?") {
|
|
2172
|
+
const end2 = source.indexOf(">", lt + 2);
|
|
2173
|
+
i = end2 === -1 ? source.length : end2 + 1;
|
|
2174
|
+
continue;
|
|
2175
|
+
}
|
|
2176
|
+
const closing = source[lt + 1] === "/";
|
|
2177
|
+
const nameMatch = /^[A-Za-z][A-Za-z0-9:-]{0,40}/.exec(source.slice(lt + (closing ? 2 : 1), lt + 45));
|
|
2178
|
+
let end = -1;
|
|
2179
|
+
let quote = "";
|
|
2180
|
+
for (let j = lt + 1; j < source.length; j += 1) {
|
|
2181
|
+
const char = source[j];
|
|
2182
|
+
if (quote) {
|
|
2183
|
+
if (char === quote) quote = "";
|
|
2184
|
+
} else if (char === '"' || char === "'") quote = char;
|
|
2185
|
+
else if (char === ">") {
|
|
2186
|
+
end = j;
|
|
2187
|
+
break;
|
|
1882
2188
|
}
|
|
1883
|
-
return out;
|
|
1884
2189
|
}
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
2190
|
+
if (!nameMatch || end === -1) {
|
|
2191
|
+
pushText(source.slice(lt, end === -1 ? source.length : lt + 1));
|
|
2192
|
+
i = end === -1 ? source.length : lt + 1;
|
|
2193
|
+
continue;
|
|
2194
|
+
}
|
|
2195
|
+
const tag = nameMatch[0].toLowerCase();
|
|
2196
|
+
const body = source.slice(lt + (closing ? 2 : 1) + nameMatch[0].length, end);
|
|
2197
|
+
i = end + 1;
|
|
2198
|
+
if (closing) {
|
|
2199
|
+
for (let s = stack.length - 1; s > 0; s -= 1) {
|
|
2200
|
+
if (stack[s].tag === tag) {
|
|
2201
|
+
stack.length = s;
|
|
2202
|
+
break;
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
continue;
|
|
2206
|
+
}
|
|
2207
|
+
if (count >= MAX_NODES2) continue;
|
|
2208
|
+
const element = { type: "element", tag, attrs: parseAttributes2(body), children: [] };
|
|
2209
|
+
stack[stack.length - 1].children.push(element);
|
|
2210
|
+
count += 1;
|
|
2211
|
+
const selfClosing = /\/\s*$/.test(body);
|
|
2212
|
+
if (!selfClosing && stack.length < MAX_DEPTH2) stack.push(element);
|
|
1906
2213
|
}
|
|
2214
|
+
return root.children;
|
|
1907
2215
|
};
|
|
1908
|
-
var
|
|
1909
|
-
const out =
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
if (
|
|
2216
|
+
var clean = (nodes, ctx, depth, inAnnotation) => {
|
|
2217
|
+
const out = [];
|
|
2218
|
+
if (!Array.isArray(nodes) || depth > MAX_DEPTH2) return out;
|
|
2219
|
+
for (const node of nodes) {
|
|
2220
|
+
if (ctx.budget <= 0) break;
|
|
2221
|
+
if (typeof node === "string") {
|
|
2222
|
+
ctx.budget -= 1;
|
|
2223
|
+
if (node) out.push({ type: "text", value: node });
|
|
2224
|
+
continue;
|
|
2225
|
+
}
|
|
2226
|
+
if (!node || typeof node !== "object") continue;
|
|
2227
|
+
ctx.budget -= 1;
|
|
2228
|
+
if (node.type === "text") {
|
|
2229
|
+
if (typeof node.value === "string" && node.value) out.push({ type: "text", value: node.value });
|
|
2230
|
+
continue;
|
|
2231
|
+
}
|
|
2232
|
+
if (node.type !== "element" || typeof node.tag !== "string" || inAnnotation) continue;
|
|
2233
|
+
const tag = node.tag.toLowerCase();
|
|
2234
|
+
if (!TAGS.has(tag)) continue;
|
|
2235
|
+
const attrs = cleanAttributes2(tag, node.attrs && typeof node.attrs === "object" ? node.attrs : {});
|
|
2236
|
+
if (!attrs) continue;
|
|
2237
|
+
const children = clean(node.children, ctx, depth + 1, tag === "annotation");
|
|
2238
|
+
out.push({ type: "element", tag, attrs, children });
|
|
1914
2239
|
}
|
|
1915
2240
|
return out;
|
|
1916
2241
|
};
|
|
1917
|
-
var
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
2242
|
+
var cleanMathResult = (result) => {
|
|
2243
|
+
let nodes;
|
|
2244
|
+
if (typeof result === "string") nodes = tokenize(result);
|
|
2245
|
+
else if (Array.isArray(result)) nodes = result;
|
|
2246
|
+
else if (result && typeof result === "object") nodes = [result];
|
|
2247
|
+
else return [];
|
|
2248
|
+
const top = nodes.filter(
|
|
2249
|
+
(node) => node && typeof node === "object" && node.type === "element" && String(node.tag).toLowerCase() === "math"
|
|
2250
|
+
);
|
|
2251
|
+
return clean(top, { budget: MAX_NODES2 }, 0, false);
|
|
2252
|
+
};
|
|
2253
|
+
|
|
2254
|
+
// shared/render/math-notes.mjs
|
|
2255
|
+
var DEFAULT_FOOTNOTES_LABEL = "Footnotes";
|
|
2256
|
+
var DEFAULT_FOOTNOTE_BACK_LABEL = "Back to reference {n}";
|
|
2257
|
+
var DEFAULT_FOOTNOTE_PREFIX = "mex-";
|
|
2258
|
+
var PREFIX = /^[A-Za-z][A-Za-z0-9_-]{0,40}$/;
|
|
2259
|
+
var label = (value, fallback) => {
|
|
2260
|
+
if (typeof value !== "string") return fallback;
|
|
2261
|
+
const clean2 = value.trim();
|
|
2262
|
+
return clean2 && clean2.length <= 80 ? clean2 : fallback;
|
|
2263
|
+
};
|
|
2264
|
+
var footnoteOptions = (options) => {
|
|
2265
|
+
const source = isPlainObject2(options && options.footnotes) ? options.footnotes : {};
|
|
2266
|
+
return {
|
|
2267
|
+
label: label(source.label, DEFAULT_FOOTNOTES_LABEL),
|
|
2268
|
+
backLabel: label(source.backLabel, DEFAULT_FOOTNOTE_BACK_LABEL),
|
|
2269
|
+
prefix: typeof source.prefix === "string" && PREFIX.test(source.prefix) ? source.prefix : DEFAULT_FOOTNOTE_PREFIX
|
|
1929
2270
|
};
|
|
1930
|
-
if (!isObject2(data)) return;
|
|
1931
|
-
for (const key of Object.keys(fields))
|
|
1932
|
-
if (Object.prototype.hasOwnProperty.call(data, key)) walk(fields[key], data[key], [key], 0);
|
|
1933
2271
|
};
|
|
1934
|
-
var
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
}
|
|
1943
|
-
return null;
|
|
2272
|
+
var createFootnoteNumbers = () => {
|
|
2273
|
+
const used = /* @__PURE__ */ new Map();
|
|
2274
|
+
let count = 0;
|
|
2275
|
+
return {
|
|
2276
|
+
add(id) {
|
|
2277
|
+
const seen = (used.get(id) || 0) + 1;
|
|
2278
|
+
used.set(id, seen);
|
|
2279
|
+
count += 1;
|
|
2280
|
+
return { n: count, anchor: seen === 1 ? id : `${id}-${seen}` };
|
|
1944
2281
|
}
|
|
1945
|
-
|
|
1946
|
-
|
|
2282
|
+
};
|
|
2283
|
+
};
|
|
2284
|
+
var renderMathNodes = (options, tex, display) => {
|
|
2285
|
+
if (!options || typeof options.math !== "function" || !tex.trim()) return [];
|
|
2286
|
+
let result;
|
|
2287
|
+
try {
|
|
2288
|
+
result = options.math(tex, { display });
|
|
2289
|
+
} catch {
|
|
2290
|
+
return [];
|
|
1947
2291
|
}
|
|
1948
|
-
return
|
|
2292
|
+
return cleanMathResult(result);
|
|
1949
2293
|
};
|
|
1950
|
-
var
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
const
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
* (`html` for inline fields, `plain` for text fields).
|
|
1982
|
-
* @param {unknown} data - Block data.
|
|
1983
|
-
* @returns {Array<{ path: Array<string|number>, kind: 'html'|'plain', value: string }>} Fields.
|
|
1984
|
-
*/
|
|
1985
|
-
fields: (data) => {
|
|
1986
|
-
const out = [];
|
|
1987
|
-
eachLeaf(schema, data, (field, value, path) => {
|
|
1988
|
-
if (typeof value !== "string") return;
|
|
1989
|
-
if (field.type === "inline") out.push({ path, kind: "html", value });
|
|
1990
|
-
else if (field.type === "text") out.push({ path, kind: "plain", value });
|
|
1991
|
-
});
|
|
1992
|
-
return out;
|
|
1993
|
-
},
|
|
1994
|
-
/**
|
|
1995
|
-
* Non-empty URL values: `{ path, value }`.
|
|
1996
|
-
* @param {unknown} data - Block data.
|
|
1997
|
-
* @returns {Array<{ path: Array<string|number>, value: string }>} URLs.
|
|
1998
|
-
*/
|
|
1999
|
-
urls: (data) => {
|
|
2000
|
-
const out = [];
|
|
2001
|
-
eachLeaf(schema, data, (field, value, path) => {
|
|
2002
|
-
if (field.type === "url" && typeof value === "string" && value) out.push({ path, value });
|
|
2003
|
-
});
|
|
2004
|
-
return out;
|
|
2294
|
+
var mathElement = (options, tex, kind) => {
|
|
2295
|
+
const math = renderMathNodes(options, tex, kind.display);
|
|
2296
|
+
const attrs = {
|
|
2297
|
+
class: kind.className || (kind.display ? "mex-math mex-math-display" : "mex-math"),
|
|
2298
|
+
"data-mex-math": kind.display ? "display" : "inline"
|
|
2299
|
+
};
|
|
2300
|
+
const children = math.length ? math : kind.display ? `\\[${tex}\\]` : `\\(${tex}\\)`;
|
|
2301
|
+
return el(kind.block ? "div" : "span", attrs, children);
|
|
2302
|
+
};
|
|
2303
|
+
var createFootnoteTree = (options, renderNote) => {
|
|
2304
|
+
const { label: listLabel, backLabel, prefix } = footnoteOptions(options);
|
|
2305
|
+
const numbers = createFootnoteNumbers();
|
|
2306
|
+
const items = [];
|
|
2307
|
+
const labelId = `${prefix}footnotes-label`;
|
|
2308
|
+
return {
|
|
2309
|
+
marker(node) {
|
|
2310
|
+
const { n, anchor } = numbers.add(node.attrs["data-mex-footnote"]);
|
|
2311
|
+
items.push({ n, anchor, note: node.note || [] });
|
|
2312
|
+
return el(
|
|
2313
|
+
"sup",
|
|
2314
|
+
{ class: "mex-footnote-ref" },
|
|
2315
|
+
el(
|
|
2316
|
+
"a",
|
|
2317
|
+
{
|
|
2318
|
+
href: `#${prefix}fn-${anchor}`,
|
|
2319
|
+
id: `${prefix}fnref-${anchor}`,
|
|
2320
|
+
"aria-describedby": labelId
|
|
2321
|
+
},
|
|
2322
|
+
String(n)
|
|
2323
|
+
)
|
|
2324
|
+
);
|
|
2005
2325
|
},
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2326
|
+
section() {
|
|
2327
|
+
if (!items.length) return null;
|
|
2328
|
+
return el("section", { class: "mex-footnotes", "aria-labelledby": labelId }, [
|
|
2329
|
+
el("h2", { id: labelId, class: "mex-footnotes-label" }, listLabel),
|
|
2330
|
+
el(
|
|
2331
|
+
"ol",
|
|
2332
|
+
{ class: "mex-footnotes-list" },
|
|
2333
|
+
items.map(
|
|
2334
|
+
(item) => el("li", { id: `${prefix}fn-${item.anchor}`, class: "mex-footnote" }, [
|
|
2335
|
+
renderNote(item.note),
|
|
2336
|
+
" ",
|
|
2337
|
+
el(
|
|
2338
|
+
"a",
|
|
2339
|
+
{
|
|
2340
|
+
href: `#${prefix}fnref-${item.anchor}`,
|
|
2341
|
+
class: "mex-footnote-back",
|
|
2342
|
+
"aria-label": backLabel.replace(/\{n\}/g, String(item.n))
|
|
2343
|
+
},
|
|
2344
|
+
"\u21A9"
|
|
2345
|
+
)
|
|
2346
|
+
])
|
|
2347
|
+
)
|
|
2348
|
+
)
|
|
2349
|
+
]);
|
|
2017
2350
|
}
|
|
2018
|
-
}
|
|
2019
|
-
compiled.set(result, result);
|
|
2020
|
-
if (definition && typeof definition === "object") compiled.set(definition, result);
|
|
2021
|
-
return result;
|
|
2022
|
-
};
|
|
2023
|
-
var copyData = (value) => {
|
|
2024
|
-
if (Array.isArray(value)) return value.map(copyData);
|
|
2025
|
-
if (isObject2(value)) {
|
|
2026
|
-
const out = {};
|
|
2027
|
-
for (const [key, child] of Object.entries(value)) out[key] = copyData(child);
|
|
2028
|
-
return out;
|
|
2029
|
-
}
|
|
2030
|
-
return value;
|
|
2031
|
-
};
|
|
2032
|
-
var listCache = /* @__PURE__ */ new WeakMap();
|
|
2033
|
-
var compileBlockList = (list) => {
|
|
2034
|
-
if (!Array.isArray(list)) return /* @__PURE__ */ new Map();
|
|
2035
|
-
if (listCache.has(list)) return listCache.get(list);
|
|
2036
|
-
const map = /* @__PURE__ */ new Map();
|
|
2037
|
-
for (const definition of list) {
|
|
2038
|
-
const def = compileBlock(definition);
|
|
2039
|
-
map.set(def.name, def);
|
|
2040
|
-
}
|
|
2041
|
-
listCache.set(list, map);
|
|
2042
|
-
return map;
|
|
2351
|
+
};
|
|
2043
2352
|
};
|
|
2044
2353
|
|
|
2045
2354
|
// shared/toc.mjs
|