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.
Files changed (95) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +140 -62
  3. package/bin/magic-editor-x.mjs +55 -8
  4. package/dist/admin/{AuditPage-guB0SiGS.mjs → AuditPage-Be78C7EC.mjs} +4 -3
  5. package/dist/admin/{AuditPage-C2u6z4aN.js → AuditPage-iQzpjH8H.js} +7 -6
  6. package/dist/admin/{ConfigurationPage-DiEpF1Rr.mjs → ConfigurationPage-C9CPBfWy.mjs} +186 -6
  7. package/dist/admin/{ConfigurationPage-D6uya-J1.js → ConfigurationPage-DefuBeYO.js} +191 -11
  8. package/dist/admin/Content-BttG50Mc.mjs +360 -0
  9. package/dist/admin/Content-V5MRBsI3.js +362 -0
  10. package/dist/admin/{CustomBlocksPage-Byt10-6c.mjs → CustomBlocksPage-DB5nnCsn.mjs} +5 -4
  11. package/dist/admin/{CustomBlocksPage-DP3h_wNd.js → CustomBlocksPage-Dg2rM3F4.js} +8 -7
  12. package/dist/admin/EntryWidgets-B8YA0Zxy.mjs +199 -0
  13. package/dist/admin/EntryWidgets-BcXAAx3F.js +201 -0
  14. package/dist/admin/{MentionsWidget-sMkM9mHX.mjs → MentionsWidget-CJPZDk9Z.mjs} +2 -2
  15. package/dist/admin/{MentionsWidget-C2OCAmqq.js → MentionsWidget-DUz6YVIG.js} +2 -2
  16. package/dist/admin/{useT-CLPhBmBC.mjs → SectionCard-8ZNHkvn9.mjs} +2 -12
  17. package/dist/admin/{useT-BXJLIPN4.js → SectionCard-Bs-xiiH1.js} +0 -10
  18. package/dist/admin/{TemplatesPage-Yp4OqFE2.mjs → TemplatesPage-VsZ_Mc0R.mjs} +6 -5
  19. package/dist/admin/{TemplatesPage-DrSJdteI.js → TemplatesPage-dx4_yd_t.js} +13 -12
  20. package/dist/admin/{api-bix9RLLI.js → api-4AYzwS4-.js} +9 -1
  21. package/dist/admin/{api-2ZRpHM3d.mjs → api-CcTYyckq.mjs} +9 -1
  22. package/dist/admin/{de-zcV8D7nt.js → de-B6rdcOqQ.js} +103 -1
  23. package/dist/admin/{de-1cFMs-4c.mjs → de-BWfR2jTg.mjs} +8 -1
  24. package/dist/admin/{de-DiCZrmH8.mjs → de-Bip0sBRT.mjs} +19 -1
  25. package/dist/admin/{de-Dn8athM8.js → de-BrPR4sUB.js} +8 -1
  26. package/dist/admin/{de-CKz6CG3V.mjs → de-CQA8hOpl.mjs} +103 -1
  27. package/dist/admin/{de-CbBDnXeT.js → de-CnnxKXj7.js} +19 -1
  28. package/dist/admin/{de-BhhGss1l.js → de-Dss5POqk.js} +12 -1
  29. package/dist/admin/{de-BNPIGqhs.mjs → de-zgHCYTLH.mjs} +12 -1
  30. package/dist/admin/{en-CIZ5Ggod.js → en--JjAHbpP.js} +8 -1
  31. package/dist/admin/{en-cYzqbASF.mjs → en-BCKaVgBM.mjs} +103 -1
  32. package/dist/admin/{en-B9ApE1y1.js → en-CJ17Sp_e.js} +12 -1
  33. package/dist/admin/{en-BMWhILnj.js → en-CbGkcq0Q.js} +103 -1
  34. package/dist/admin/{en-DCPMqFIa.mjs → en-Cd6Jk-J0.mjs} +19 -1
  35. package/dist/admin/{en-CpehF0Kv.js → en-D69Fe9ZO.js} +19 -1
  36. package/dist/admin/{en-Dc9y-6n9.mjs → en-Dr58wBAo.mjs} +8 -1
  37. package/dist/admin/{en-gFLeK9Ng.mjs → en-Uhm7OouM.mjs} +12 -1
  38. package/dist/admin/entry-panel-events-0msyPrAD.js +18 -0
  39. package/dist/admin/entry-panel-events-XRuUoLZ9.mjs +19 -0
  40. package/dist/admin/{es-D2Kw6E4N.mjs → es-B2Hkkbw9.mjs} +8 -1
  41. package/dist/admin/{es-BmwBgEgz.mjs → es-BMkmfH88.mjs} +12 -1
  42. package/dist/admin/{es-Chs37IBR.mjs → es-Bz8d72Fa.mjs} +19 -1
  43. package/dist/admin/{es-CQPh8PXw.js → es-C8UotT8O.js} +103 -1
  44. package/dist/admin/{es-CawpzwyC.js → es-CcEDZpVQ.js} +19 -1
  45. package/dist/admin/{es-C0W31rl8.js → es-DJm3HFJt.js} +12 -1
  46. package/dist/admin/{es-C4IRHV5d.js → es-YvaTAtqY.js} +8 -1
  47. package/dist/admin/{es-DCamt1ek.mjs → es-pvPfNAld.mjs} +103 -1
  48. package/dist/admin/{fr-BOvvfEH7.mjs → fr-BvPjRiwr.mjs} +8 -1
  49. package/dist/admin/{fr-Dp5-XP29.mjs → fr-CKHZ0xxU.mjs} +19 -1
  50. package/dist/admin/{fr-iGeIfEcU.js → fr-CRM9VuAq.js} +12 -1
  51. package/dist/admin/{fr-CMWBNE5D.mjs → fr-CrIHmKYX.mjs} +12 -1
  52. package/dist/admin/{fr-COOsqexl.js → fr-Cx29jQ_g.js} +19 -1
  53. package/dist/admin/{fr-oW0t8bT5.mjs → fr-D4tL6Ag2.mjs} +103 -1
  54. package/dist/admin/{fr-Zkb8vfjN.js → fr-Di-U-rAH.js} +8 -1
  55. package/dist/admin/{fr-DpC44Ol8.js → fr-DrUYv2jh.js} +103 -1
  56. package/dist/admin/{index-BVjf1gVC.mjs → index-C4ksUkEm.mjs} +9183 -6353
  57. package/dist/admin/{index-64wc26Bl.js → index-C5D3VqLq.js} +9170 -6340
  58. package/dist/admin/{index-D_Fv8Non.mjs → index-CMYCZWOh.mjs} +1053 -190
  59. package/dist/admin/{index-D6Z7i8ba.js → index-DRyctF9s.js} +961 -98
  60. package/dist/admin/index.js +1 -1
  61. package/dist/admin/index.mjs +2 -2
  62. package/dist/admin/{math-vsK_06ZR.js → math-D6jmskGS.js} +1 -1
  63. package/dist/admin/{math-CIQ4Z_mY.mjs → math-DntdSWKX.mjs} +1 -1
  64. package/dist/admin/{pt-DALDvfBn.mjs → pt-B8x7v-Xw.mjs} +19 -1
  65. package/dist/admin/{pt-DXy7G1x7.js → pt-BYn2xx78.js} +19 -1
  66. package/dist/admin/{pt-Bo0Pm_Pt.js → pt-CojQcz-p.js} +103 -1
  67. package/dist/admin/{pt-uGpfRQLC.mjs → pt-CuoIihKx.mjs} +103 -1
  68. package/dist/admin/{pt-1IUyx6ae.js → pt-CzrN_3ui.js} +8 -1
  69. package/dist/admin/{pt-DFNgZ5_k.mjs → pt-DDlPJYtB.mjs} +12 -1
  70. package/dist/admin/{pt-BHmXk2d9.js → pt-DPVAycXJ.js} +12 -1
  71. package/dist/admin/{pt-etwsg3G4.mjs → pt-DdGagO99.mjs} +8 -1
  72. package/dist/admin/useT-Bpw__IXT.js +12 -0
  73. package/dist/admin/useT-Cb-R3kyA.mjs +13 -0
  74. package/dist/blocks/index.d.mts +124 -0
  75. package/dist/blocks/index.d.ts +124 -0
  76. package/dist/blocks/index.js +172 -3
  77. package/dist/blocks/index.mjs +172 -3
  78. package/dist/math/index.js +6 -2
  79. package/dist/math/index.mjs +6 -2
  80. package/dist/react/index.js +1376 -1067
  81. package/dist/react/index.mjs +1376 -1067
  82. package/dist/render/index.d.mts +22 -0
  83. package/dist/render/index.d.ts +22 -0
  84. package/dist/render/index.js +1376 -1067
  85. package/dist/render/index.mjs +1376 -1067
  86. package/dist/server/index.js +28894 -24197
  87. package/dist/server/index.mjs +28893 -24196
  88. package/dist/server/mcp-worker.js +11319 -0
  89. package/dist/vue/index.js +1376 -1067
  90. package/dist/vue/index.mjs +1376 -1067
  91. package/package.json +7 -7
  92. package/schema/magic-editor-x.schema.json +9 -1
  93. package/types/blocks.d.ts +124 -0
  94. package/types/index.d.ts +10 -1
  95. package/types/render.d.ts +22 -0
@@ -167,3 +167,127 @@ export const BLOCK_LIMITS: Readonly<{
167
167
  maxValues: number;
168
168
  maxUrl: number;
169
169
  }>;
170
+
171
+ /* ------------------------------------------------------------------ 2.5 */
172
+
173
+ /** Attribute types of an inline annotation. */
174
+ export type InlineAnnotationFieldType = 'text' | 'enum' | 'url';
175
+
176
+ export interface InlineAnnotationAttributeInput {
177
+ type: InlineAnnotationFieldType;
178
+ label?: string;
179
+ /** Without a required value the annotation is unwrapped on save (its text stays). */
180
+ required?: boolean;
181
+ /** `text`: 1-1000 characters (default 200). */
182
+ max?: number;
183
+ /** `enum`: 1-50 distinct strings. */
184
+ values?: readonly string[];
185
+ /** `url`: subset of http, https, mailto, tel (default http + https). */
186
+ schemes?: ReadonlyArray<'http' | 'https' | 'mailto' | 'tel'>;
187
+ /** `url`: allow site-relative URLs (default true). */
188
+ relative?: boolean;
189
+ }
190
+
191
+ /** What `render` and `resolve` see of one annotation (clean values). */
192
+ export interface InlineAnnotationUse {
193
+ name: string;
194
+ attrs: Record<string, string>;
195
+ text: string;
196
+ /** Value from `resolve` (server output) or the `resolveAnnotation` render option. */
197
+ resolved?: string | Record<string, unknown>;
198
+ }
199
+
200
+ /** The one element that wraps the annotated text (validated: allowed tags and attributes only). */
201
+ export interface InlineAnnotationWrapper {
202
+ tag:
203
+ | 'abbr'
204
+ | 'dfn'
205
+ | 'span'
206
+ | 'a'
207
+ | 'mark'
208
+ | 'cite'
209
+ | 'q'
210
+ | 'small'
211
+ | 'em'
212
+ | 'strong'
213
+ | 'b'
214
+ | 'i'
215
+ | 'u'
216
+ | 's'
217
+ | 'time'
218
+ | 'data'
219
+ | 'bdi'
220
+ | 'kbd'
221
+ | 'var'
222
+ | 'ins'
223
+ | 'del';
224
+ /** `title`, `class`, `lang`, `dir`, `href` (only on `a`), `datetime`, `value`, `cite`, `aria-label`, `data-*` (not `data-mex-*`). */
225
+ attrs?: Record<string, string | number | null | undefined | false>;
226
+ }
227
+
228
+ /** Context of a server-side `resolve` call (Content API `?mex=`, GraphQL `…Rendered`). */
229
+ export interface InlineAnnotationResolveContext {
230
+ status: 'draft' | 'published';
231
+ /**
232
+ * Permission-aware lookup: only `api::` types the caller may `find`, the
233
+ * query sanitised with the caller's auth, the request's publication status,
234
+ * at most 100 rows, every row sanitised for output.
235
+ */
236
+ find(
237
+ uid: string,
238
+ query?: { filters?: Record<string, unknown>; fields?: string[]; locale?: string | null; limit?: number }
239
+ ): Promise<Array<Record<string, unknown>>>;
240
+ }
241
+
242
+ export interface InlineAnnotationDefinitionInput {
243
+ /** `/^[a-z][a-z0-9-]{1,39}$/`; `abbreviation` is built in. */
244
+ name: string;
245
+ label?: string;
246
+ description?: string;
247
+ /** 0-8 attributes, keys `/^[a-z][a-z0-9]{0,23}$/`, stored as `data-mex-a-<key>`. */
248
+ attributes: Record<string, InlineAnnotationAttributeInput>;
249
+ /** Presets that offer the annotation without the field option `inlineAnnotations`. */
250
+ presets?: ReadonlyArray<'full' | 'article' | 'basic' | 'minimal'>;
251
+ /** Keyboard shortcut of the editor tool: one of `ANNOTATION_SHORTCUTS` (Ctrl on Windows/Linux). */
252
+ shortcut?: 'CMD+SHIFT+0' | 'CMD+SHIFT+1' | 'CMD+SHIFT+8';
253
+ /**
254
+ * Server only: one call per response with every distinct use (at most 200);
255
+ * return the values in the same order (string up to 2000 characters or a plain object).
256
+ */
257
+ resolve?: (
258
+ items: ReadonlyArray<{ attrs: Record<string, string>; locale: string | null }>,
259
+ context: InlineAnnotationResolveContext
260
+ ) => Promise<ReadonlyArray<unknown>> | ReadonlyArray<unknown>;
261
+ /** Wrapper of the annotated text; `false` renders the text only; null/undefined/throw = default span. */
262
+ render?: (annotation: InlineAnnotationUse) => InlineAnnotationWrapper | false | null | undefined;
263
+ }
264
+
265
+ export type InlineAnnotationDefinition = Readonly<
266
+ Required<Pick<InlineAnnotationDefinitionInput, 'name' | 'label'>> &
267
+ Omit<InlineAnnotationDefinitionInput, 'name' | 'label' | 'attributes' | 'presets'> & {
268
+ attributes: Readonly<Record<string, Readonly<InlineAnnotationAttributeInput & { required: boolean }>>>;
269
+ presets: readonly string[];
270
+ }
271
+ >;
272
+
273
+ export function defineInlineAnnotation(
274
+ definition: InlineAnnotationDefinitionInput
275
+ ): InlineAnnotationDefinition;
276
+ export function annotationJsonSchema(definition: InlineAnnotationDefinition): Record<string, unknown>;
277
+ /** The built-in abbreviation (`title`, required): renders `<abbr title>`. */
278
+ export const abbreviationAnnotation: InlineAnnotationDefinition;
279
+ export const ANNOTATION_ATTRIBUTE: 'data-mex-annotation';
280
+ export const ANNOTATION_VALUE_PREFIX: 'data-mex-a-';
281
+ export const ANNOTATION_FIELD_TYPES: readonly InlineAnnotationFieldType[];
282
+ export const ANNOTATION_PRESETS: readonly ['full', 'article', 'basic', 'minimal'];
283
+ export const ANNOTATION_SHORTCUTS: readonly ['CMD+SHIFT+0', 'CMD+SHIFT+1', 'CMD+SHIFT+8'];
284
+ export const ANNOTATION_RENDER_TAGS: readonly InlineAnnotationWrapper['tag'][];
285
+ export const ANNOTATION_LIMITS: Readonly<{
286
+ attributes: number;
287
+ text: number;
288
+ textDefault: number;
289
+ values: number;
290
+ registered: number;
291
+ label: number;
292
+ resolveItems: number;
293
+ }>;
@@ -19,15 +19,25 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // shared/blocks/index.mjs
20
20
  var index_exports = {};
21
21
  __export(index_exports, {
22
+ ANNOTATION_ATTRIBUTE: () => ANNOTATION_ATTRIBUTE,
23
+ ANNOTATION_FIELD_TYPES: () => ANNOTATION_FIELD_TYPES,
24
+ ANNOTATION_LIMITS: () => ANNOTATION_LIMITS,
25
+ ANNOTATION_PRESETS: () => ANNOTATION_PRESETS,
26
+ ANNOTATION_RENDER_TAGS: () => ANNOTATION_RENDER_TAGS,
27
+ ANNOTATION_SHORTCUTS: () => ANNOTATION_SHORTCUTS,
28
+ ANNOTATION_VALUE_PREFIX: () => ANNOTATION_VALUE_PREFIX,
22
29
  BLOCK_FIELD_TYPES: () => BLOCK_FIELD_TYPES,
23
30
  BLOCK_LIMITS: () => BLOCK_LIMITS,
24
31
  BLOCK_PRESETS: () => BLOCK_PRESETS,
25
32
  BlockDefinitionError: () => BlockDefinitionError,
26
33
  RESERVED_BLOCK_NAMES: () => RESERVED_BLOCK_NAMES,
27
34
  SDK_COMPATIBLE_NAMES: () => SDK_COMPATIBLE_NAMES,
35
+ abbreviationAnnotation: () => abbreviationAnnotation,
36
+ annotationJsonSchema: () => annotationJsonSchema,
28
37
  blockJsonSchema: () => blockJsonSchema,
29
38
  blockNameProblem: () => blockNameProblem,
30
- defineBlock: () => defineBlock
39
+ defineBlock: () => defineBlock,
40
+ defineInlineAnnotation: () => defineInlineAnnotation
31
41
  });
32
42
  module.exports = __toCommonJS(index_exports);
33
43
 
@@ -95,11 +105,15 @@ var INTERNAL_LINK_RULES = Object.freeze({
95
105
  });
96
106
  var MATH_ATTRIBUTE = "data-mex-math";
97
107
  var FOOTNOTE_ATTRIBUTES = Object.freeze(["data-mex-footnote", "data-mex-note"]);
108
+ var INLINE_FORMAT_ATTRIBUTES = Object.freeze({
109
+ span: ["data-mex-color", "data-mex-annotation", "data-mex-a-*"],
110
+ mark: ["data-mex-highlight"]
111
+ });
98
112
  var INLINE_ATTRIBUTES = Object.freeze({
99
113
  a: ["href", "target", "rel", "title", ...INTERNAL_LINK_ATTRIBUTES],
100
- span: ["class", "data-tooltip", MATH_ATTRIBUTE],
114
+ span: ["class", "data-tooltip", MATH_ATTRIBUTE, ...INLINE_FORMAT_ATTRIBUTES.span],
101
115
  sup: [...FOOTNOTE_ATTRIBUTES],
102
- mark: ["class"],
116
+ mark: ["class", ...INLINE_FORMAT_ATTRIBUTES.mark],
103
117
  u: ["class"],
104
118
  s: ["class"],
105
119
  code: ["class"]
@@ -640,3 +654,158 @@ var copyData = (value) => {
640
654
  }
641
655
  return value;
642
656
  };
657
+
658
+ // shared/render/nodes.mjs
659
+ var STYLE_PROPERTIES = Object.freeze(["object-position"]);
660
+
661
+ // shared/blocks/annotations.mjs
662
+ var ANNOTATION_ATTRIBUTE = "data-mex-annotation";
663
+ var ANNOTATION_VALUE_PREFIX = "data-mex-a-";
664
+ var ANNOTATION_NAME = /^[a-z][a-z0-9-]{1,39}$/;
665
+ var ANNOTATION_KEY = /^[a-z][a-z0-9]{0,23}$/;
666
+ var ANNOTATION_FIELD_TYPES = Object.freeze(["text", "enum", "url"]);
667
+ var ANNOTATION_LIMITS = Object.freeze({
668
+ attributes: 8,
669
+ text: 1e3,
670
+ textDefault: 200,
671
+ values: 50,
672
+ registered: 50,
673
+ label: 100,
674
+ resolveItems: 200
675
+ });
676
+ var ANNOTATION_PRESETS = Object.freeze(["full", "article", "basic", "minimal"]);
677
+ var ANNOTATION_RENDER_TAGS = Object.freeze([
678
+ "abbr",
679
+ "dfn",
680
+ "span",
681
+ "a",
682
+ "mark",
683
+ "cite",
684
+ "q",
685
+ "small",
686
+ "em",
687
+ "strong",
688
+ "b",
689
+ "i",
690
+ "u",
691
+ "s",
692
+ "time",
693
+ "data",
694
+ "bdi",
695
+ "kbd",
696
+ "var",
697
+ "ins",
698
+ "del"
699
+ ]);
700
+ var ANNOTATION_SHORTCUTS = Object.freeze(["CMD+SHIFT+0", "CMD+SHIFT+1", "CMD+SHIFT+8"]);
701
+ var ABBREVIATION = "abbreviation";
702
+ var isObject2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
703
+ var fail2 = (name, message, code = "INVALID_DEFINITION") => {
704
+ throw new BlockDefinitionError(`Magic Editor X inline annotation ${name}: ${message}`, code);
705
+ };
706
+ var defined = /* @__PURE__ */ new WeakSet();
707
+ var normalizeAttribute = (where, input) => {
708
+ if (!isObject2(input)) fail2(where, 'an attribute must be an object with a "type"');
709
+ const { type } = input;
710
+ if (!ANNOTATION_FIELD_TYPES.includes(type)) fail2(where, `unknown attribute type ${JSON.stringify(type)}`);
711
+ const allowed = { text: ["max"], enum: ["values"], url: ["schemes", "relative"] }[type];
712
+ for (const key of Object.keys(input))
713
+ if (!["type", "label", "required", ...allowed].includes(key))
714
+ fail2(where, `unknown option "${key}" for a ${type} attribute`);
715
+ const out = { type, required: input.required === true };
716
+ if (input.label !== void 0) {
717
+ if (typeof input.label !== "string" || input.label.length > ANNOTATION_LIMITS.label)
718
+ fail2(where, `"label" must be a string of at most ${ANNOTATION_LIMITS.label} characters`);
719
+ out.label = input.label;
720
+ }
721
+ if (input.required !== void 0 && typeof input.required !== "boolean")
722
+ fail2(where, '"required" must be a boolean');
723
+ if (type === "text") {
724
+ const max = input.max === void 0 ? ANNOTATION_LIMITS.textDefault : input.max;
725
+ if (!Number.isInteger(max) || max < 1 || max > ANNOTATION_LIMITS.text)
726
+ fail2(where, `"max" must be an integer from 1 to ${ANNOTATION_LIMITS.text}`);
727
+ out.max = max;
728
+ } else if (type === "enum") {
729
+ const { values } = input;
730
+ 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)
731
+ fail2(where, `"values" must be 1 to ${ANNOTATION_LIMITS.values} distinct strings`);
732
+ out.values = Object.freeze([...values]);
733
+ } else {
734
+ const schemes = input.schemes === void 0 ? ["http", "https"] : input.schemes;
735
+ if (!Array.isArray(schemes) || !schemes.length || !schemes.every((scheme) => LINK_SCHEMES.includes(scheme)))
736
+ fail2(where, `"schemes" must be a non-empty subset of ${LINK_SCHEMES.join(", ")}`);
737
+ if (input.relative !== void 0 && typeof input.relative !== "boolean")
738
+ fail2(where, '"relative" must be a boolean');
739
+ out.schemes = Object.freeze([...new Set(schemes)]);
740
+ out.relative = input.relative !== false;
741
+ }
742
+ return Object.freeze(out);
743
+ };
744
+ var defineInlineAnnotation = (definition) => {
745
+ if (!isObject2(definition)) fail2("(unnamed)", "the definition must be an object");
746
+ const { name } = definition;
747
+ if (typeof name !== "string" || !ANNOTATION_NAME.test(name))
748
+ fail2(JSON.stringify(name), "the name must match /^[a-z][a-z0-9-]{1,39}$/");
749
+ for (const key of Object.keys(definition))
750
+ if (!["name", "label", "description", "attributes", "presets", "resolve", "render", "shortcut"].includes(
751
+ key
752
+ ))
753
+ fail2(name, `unknown key "${key}"`);
754
+ for (const key of ["label", "description"])
755
+ if (definition[key] !== void 0 && (typeof definition[key] !== "string" || definition[key].length > (key === "label" ? 100 : 500)))
756
+ fail2(name, `"${key}" must be a short string`);
757
+ if (!isObject2(definition.attributes)) fail2(name, '"attributes" must be an object');
758
+ const keys = Object.keys(definition.attributes);
759
+ if (keys.length > ANNOTATION_LIMITS.attributes)
760
+ fail2(name, `at most ${ANNOTATION_LIMITS.attributes} attributes`);
761
+ const attributes = {};
762
+ for (const key of keys) {
763
+ if (!ANNOTATION_KEY.test(key)) fail2(name, `attribute key "${key}" must match /^[a-z][a-z0-9]{0,23}$/`);
764
+ attributes[key] = normalizeAttribute(`${name}.${key}`, definition.attributes[key]);
765
+ }
766
+ const presets = definition.presets === void 0 ? [] : definition.presets;
767
+ if (!Array.isArray(presets) || !presets.every((preset) => ANNOTATION_PRESETS.includes(preset)))
768
+ fail2(name, `"presets" must list only ${ANNOTATION_PRESETS.join(", ")}`);
769
+ if (definition.shortcut !== void 0 && !ANNOTATION_SHORTCUTS.includes(definition.shortcut))
770
+ fail2(name, `"shortcut" must be one of ${ANNOTATION_SHORTCUTS.join(", ")}`);
771
+ for (const key of ["resolve", "render"])
772
+ if (definition[key] !== void 0 && typeof definition[key] !== "function")
773
+ fail2(name, `"${key}" must be a function`);
774
+ const out = Object.freeze({
775
+ name,
776
+ label: definition.label || name,
777
+ ...definition.description ? { description: definition.description } : {},
778
+ attributes: Object.freeze(attributes),
779
+ presets: Object.freeze([...new Set(presets)]),
780
+ ...definition.shortcut ? { shortcut: definition.shortcut } : {},
781
+ ...definition.resolve ? { resolve: definition.resolve } : {},
782
+ ...definition.render ? { render: definition.render } : {}
783
+ });
784
+ defined.add(out);
785
+ return out;
786
+ };
787
+ var annotationJsonSchema = (definition) => {
788
+ const properties = {};
789
+ const required = [];
790
+ for (const [key, field] of Object.entries(definition.attributes)) {
791
+ const schema = field.type === "text" ? { type: "string", minLength: 1, maxLength: field.max } : field.type === "enum" ? { type: "string", enum: [...field.values] } : { type: "string", format: "uri-reference", maxLength: 2048 };
792
+ if (field.label) schema.title = field.label;
793
+ properties[key] = schema;
794
+ if (field.required) required.push(key);
795
+ }
796
+ return {
797
+ title: definition.label,
798
+ type: "object",
799
+ properties,
800
+ ...required.length ? { required } : {},
801
+ additionalProperties: false,
802
+ "x-mex-stored-as": `<span ${ANNOTATION_ATTRIBUTE}="${definition.name}" ${ANNOTATION_VALUE_PREFIX}<key>="\u2026">`
803
+ };
804
+ };
805
+ var abbreviationAnnotation = defineInlineAnnotation({
806
+ name: ABBREVIATION,
807
+ label: "Abbreviation",
808
+ description: "Short form with its full form (shown as a tooltip and read by screen readers).",
809
+ attributes: { title: { type: "text", max: 200, required: true, label: "Full form" } },
810
+ render: (annotation) => ({ tag: "abbr", attrs: { title: annotation.attrs.title } })
811
+ });
@@ -62,11 +62,15 @@ var INTERNAL_LINK_RULES = Object.freeze({
62
62
  });
63
63
  var MATH_ATTRIBUTE = "data-mex-math";
64
64
  var FOOTNOTE_ATTRIBUTES = Object.freeze(["data-mex-footnote", "data-mex-note"]);
65
+ var INLINE_FORMAT_ATTRIBUTES = Object.freeze({
66
+ span: ["data-mex-color", "data-mex-annotation", "data-mex-a-*"],
67
+ mark: ["data-mex-highlight"]
68
+ });
65
69
  var INLINE_ATTRIBUTES = Object.freeze({
66
70
  a: ["href", "target", "rel", "title", ...INTERNAL_LINK_ATTRIBUTES],
67
- span: ["class", "data-tooltip", MATH_ATTRIBUTE],
71
+ span: ["class", "data-tooltip", MATH_ATTRIBUTE, ...INLINE_FORMAT_ATTRIBUTES.span],
68
72
  sup: [...FOOTNOTE_ATTRIBUTES],
69
- mark: ["class"],
73
+ mark: ["class", ...INLINE_FORMAT_ATTRIBUTES.mark],
70
74
  u: ["class"],
71
75
  s: ["class"],
72
76
  code: ["class"]
@@ -607,14 +611,179 @@ var copyData = (value) => {
607
611
  }
608
612
  return value;
609
613
  };
614
+
615
+ // shared/render/nodes.mjs
616
+ var STYLE_PROPERTIES = Object.freeze(["object-position"]);
617
+
618
+ // shared/blocks/annotations.mjs
619
+ var ANNOTATION_ATTRIBUTE = "data-mex-annotation";
620
+ var ANNOTATION_VALUE_PREFIX = "data-mex-a-";
621
+ var ANNOTATION_NAME = /^[a-z][a-z0-9-]{1,39}$/;
622
+ var ANNOTATION_KEY = /^[a-z][a-z0-9]{0,23}$/;
623
+ var ANNOTATION_FIELD_TYPES = Object.freeze(["text", "enum", "url"]);
624
+ var ANNOTATION_LIMITS = Object.freeze({
625
+ attributes: 8,
626
+ text: 1e3,
627
+ textDefault: 200,
628
+ values: 50,
629
+ registered: 50,
630
+ label: 100,
631
+ resolveItems: 200
632
+ });
633
+ var ANNOTATION_PRESETS = Object.freeze(["full", "article", "basic", "minimal"]);
634
+ var ANNOTATION_RENDER_TAGS = Object.freeze([
635
+ "abbr",
636
+ "dfn",
637
+ "span",
638
+ "a",
639
+ "mark",
640
+ "cite",
641
+ "q",
642
+ "small",
643
+ "em",
644
+ "strong",
645
+ "b",
646
+ "i",
647
+ "u",
648
+ "s",
649
+ "time",
650
+ "data",
651
+ "bdi",
652
+ "kbd",
653
+ "var",
654
+ "ins",
655
+ "del"
656
+ ]);
657
+ var ANNOTATION_SHORTCUTS = Object.freeze(["CMD+SHIFT+0", "CMD+SHIFT+1", "CMD+SHIFT+8"]);
658
+ var ABBREVIATION = "abbreviation";
659
+ var isObject2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
660
+ var fail2 = (name, message, code = "INVALID_DEFINITION") => {
661
+ throw new BlockDefinitionError(`Magic Editor X inline annotation ${name}: ${message}`, code);
662
+ };
663
+ var defined = /* @__PURE__ */ new WeakSet();
664
+ var normalizeAttribute = (where, input) => {
665
+ if (!isObject2(input)) fail2(where, 'an attribute must be an object with a "type"');
666
+ const { type } = input;
667
+ if (!ANNOTATION_FIELD_TYPES.includes(type)) fail2(where, `unknown attribute type ${JSON.stringify(type)}`);
668
+ const allowed = { text: ["max"], enum: ["values"], url: ["schemes", "relative"] }[type];
669
+ for (const key of Object.keys(input))
670
+ if (!["type", "label", "required", ...allowed].includes(key))
671
+ fail2(where, `unknown option "${key}" for a ${type} attribute`);
672
+ const out = { type, required: input.required === true };
673
+ if (input.label !== void 0) {
674
+ if (typeof input.label !== "string" || input.label.length > ANNOTATION_LIMITS.label)
675
+ fail2(where, `"label" must be a string of at most ${ANNOTATION_LIMITS.label} characters`);
676
+ out.label = input.label;
677
+ }
678
+ if (input.required !== void 0 && typeof input.required !== "boolean")
679
+ fail2(where, '"required" must be a boolean');
680
+ if (type === "text") {
681
+ const max = input.max === void 0 ? ANNOTATION_LIMITS.textDefault : input.max;
682
+ if (!Number.isInteger(max) || max < 1 || max > ANNOTATION_LIMITS.text)
683
+ fail2(where, `"max" must be an integer from 1 to ${ANNOTATION_LIMITS.text}`);
684
+ out.max = max;
685
+ } else if (type === "enum") {
686
+ const { values } = input;
687
+ 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)
688
+ fail2(where, `"values" must be 1 to ${ANNOTATION_LIMITS.values} distinct strings`);
689
+ out.values = Object.freeze([...values]);
690
+ } else {
691
+ const schemes = input.schemes === void 0 ? ["http", "https"] : input.schemes;
692
+ if (!Array.isArray(schemes) || !schemes.length || !schemes.every((scheme) => LINK_SCHEMES.includes(scheme)))
693
+ fail2(where, `"schemes" must be a non-empty subset of ${LINK_SCHEMES.join(", ")}`);
694
+ if (input.relative !== void 0 && typeof input.relative !== "boolean")
695
+ fail2(where, '"relative" must be a boolean');
696
+ out.schemes = Object.freeze([...new Set(schemes)]);
697
+ out.relative = input.relative !== false;
698
+ }
699
+ return Object.freeze(out);
700
+ };
701
+ var defineInlineAnnotation = (definition) => {
702
+ if (!isObject2(definition)) fail2("(unnamed)", "the definition must be an object");
703
+ const { name } = definition;
704
+ if (typeof name !== "string" || !ANNOTATION_NAME.test(name))
705
+ fail2(JSON.stringify(name), "the name must match /^[a-z][a-z0-9-]{1,39}$/");
706
+ for (const key of Object.keys(definition))
707
+ if (!["name", "label", "description", "attributes", "presets", "resolve", "render", "shortcut"].includes(
708
+ key
709
+ ))
710
+ fail2(name, `unknown key "${key}"`);
711
+ for (const key of ["label", "description"])
712
+ if (definition[key] !== void 0 && (typeof definition[key] !== "string" || definition[key].length > (key === "label" ? 100 : 500)))
713
+ fail2(name, `"${key}" must be a short string`);
714
+ if (!isObject2(definition.attributes)) fail2(name, '"attributes" must be an object');
715
+ const keys = Object.keys(definition.attributes);
716
+ if (keys.length > ANNOTATION_LIMITS.attributes)
717
+ fail2(name, `at most ${ANNOTATION_LIMITS.attributes} attributes`);
718
+ const attributes = {};
719
+ for (const key of keys) {
720
+ if (!ANNOTATION_KEY.test(key)) fail2(name, `attribute key "${key}" must match /^[a-z][a-z0-9]{0,23}$/`);
721
+ attributes[key] = normalizeAttribute(`${name}.${key}`, definition.attributes[key]);
722
+ }
723
+ const presets = definition.presets === void 0 ? [] : definition.presets;
724
+ if (!Array.isArray(presets) || !presets.every((preset) => ANNOTATION_PRESETS.includes(preset)))
725
+ fail2(name, `"presets" must list only ${ANNOTATION_PRESETS.join(", ")}`);
726
+ if (definition.shortcut !== void 0 && !ANNOTATION_SHORTCUTS.includes(definition.shortcut))
727
+ fail2(name, `"shortcut" must be one of ${ANNOTATION_SHORTCUTS.join(", ")}`);
728
+ for (const key of ["resolve", "render"])
729
+ if (definition[key] !== void 0 && typeof definition[key] !== "function")
730
+ fail2(name, `"${key}" must be a function`);
731
+ const out = Object.freeze({
732
+ name,
733
+ label: definition.label || name,
734
+ ...definition.description ? { description: definition.description } : {},
735
+ attributes: Object.freeze(attributes),
736
+ presets: Object.freeze([...new Set(presets)]),
737
+ ...definition.shortcut ? { shortcut: definition.shortcut } : {},
738
+ ...definition.resolve ? { resolve: definition.resolve } : {},
739
+ ...definition.render ? { render: definition.render } : {}
740
+ });
741
+ defined.add(out);
742
+ return out;
743
+ };
744
+ var annotationJsonSchema = (definition) => {
745
+ const properties = {};
746
+ const required = [];
747
+ for (const [key, field] of Object.entries(definition.attributes)) {
748
+ const schema = field.type === "text" ? { type: "string", minLength: 1, maxLength: field.max } : field.type === "enum" ? { type: "string", enum: [...field.values] } : { type: "string", format: "uri-reference", maxLength: 2048 };
749
+ if (field.label) schema.title = field.label;
750
+ properties[key] = schema;
751
+ if (field.required) required.push(key);
752
+ }
753
+ return {
754
+ title: definition.label,
755
+ type: "object",
756
+ properties,
757
+ ...required.length ? { required } : {},
758
+ additionalProperties: false,
759
+ "x-mex-stored-as": `<span ${ANNOTATION_ATTRIBUTE}="${definition.name}" ${ANNOTATION_VALUE_PREFIX}<key>="\u2026">`
760
+ };
761
+ };
762
+ var abbreviationAnnotation = defineInlineAnnotation({
763
+ name: ABBREVIATION,
764
+ label: "Abbreviation",
765
+ description: "Short form with its full form (shown as a tooltip and read by screen readers).",
766
+ attributes: { title: { type: "text", max: 200, required: true, label: "Full form" } },
767
+ render: (annotation) => ({ tag: "abbr", attrs: { title: annotation.attrs.title } })
768
+ });
610
769
  export {
770
+ ANNOTATION_ATTRIBUTE,
771
+ ANNOTATION_FIELD_TYPES,
772
+ ANNOTATION_LIMITS,
773
+ ANNOTATION_PRESETS,
774
+ ANNOTATION_RENDER_TAGS,
775
+ ANNOTATION_SHORTCUTS,
776
+ ANNOTATION_VALUE_PREFIX,
611
777
  BLOCK_FIELD_TYPES,
612
778
  BLOCK_LIMITS,
613
779
  BLOCK_PRESETS,
614
780
  BlockDefinitionError,
615
781
  RESERVED_BLOCK_NAMES,
616
782
  SDK_COMPATIBLE_NAMES,
783
+ abbreviationAnnotation,
784
+ annotationJsonSchema,
617
785
  blockJsonSchema,
618
786
  blockNameProblem,
619
- defineBlock
787
+ defineBlock,
788
+ defineInlineAnnotation
620
789
  };
@@ -102,11 +102,15 @@ var INTERNAL_LINK_RULES = Object.freeze({
102
102
  var MATH_ATTRIBUTE = "data-mex-math";
103
103
  var FOOTNOTE_ATTRIBUTES = Object.freeze(["data-mex-footnote", "data-mex-note"]);
104
104
  var MAX_MATH_TEX = 1e4;
105
+ var INLINE_FORMAT_ATTRIBUTES = Object.freeze({
106
+ span: ["data-mex-color", "data-mex-annotation", "data-mex-a-*"],
107
+ mark: ["data-mex-highlight"]
108
+ });
105
109
  var INLINE_ATTRIBUTES = Object.freeze({
106
110
  a: ["href", "target", "rel", "title", ...INTERNAL_LINK_ATTRIBUTES],
107
- span: ["class", "data-tooltip", MATH_ATTRIBUTE],
111
+ span: ["class", "data-tooltip", MATH_ATTRIBUTE, ...INLINE_FORMAT_ATTRIBUTES.span],
108
112
  sup: [...FOOTNOTE_ATTRIBUTES],
109
- mark: ["class"],
113
+ mark: ["class", ...INLINE_FORMAT_ATTRIBUTES.mark],
110
114
  u: ["class"],
111
115
  s: ["class"],
112
116
  code: ["class"]
@@ -66,11 +66,15 @@ var INTERNAL_LINK_RULES = Object.freeze({
66
66
  var MATH_ATTRIBUTE = "data-mex-math";
67
67
  var FOOTNOTE_ATTRIBUTES = Object.freeze(["data-mex-footnote", "data-mex-note"]);
68
68
  var MAX_MATH_TEX = 1e4;
69
+ var INLINE_FORMAT_ATTRIBUTES = Object.freeze({
70
+ span: ["data-mex-color", "data-mex-annotation", "data-mex-a-*"],
71
+ mark: ["data-mex-highlight"]
72
+ });
69
73
  var INLINE_ATTRIBUTES = Object.freeze({
70
74
  a: ["href", "target", "rel", "title", ...INTERNAL_LINK_ATTRIBUTES],
71
- span: ["class", "data-tooltip", MATH_ATTRIBUTE],
75
+ span: ["class", "data-tooltip", MATH_ATTRIBUTE, ...INLINE_FORMAT_ATTRIBUTES.span],
72
76
  sup: [...FOOTNOTE_ATTRIBUTES],
73
- mark: ["class"],
77
+ mark: ["class", ...INLINE_FORMAT_ATTRIBUTES.mark],
74
78
  u: ["class"],
75
79
  s: ["class"],
76
80
  code: ["class"]