@rtif-sdk/web 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -0
  3. package/dist/block-drag-handler.d.ts +189 -0
  4. package/dist/block-drag-handler.d.ts.map +1 -0
  5. package/dist/block-drag-handler.js +745 -0
  6. package/dist/block-drag-handler.js.map +1 -0
  7. package/dist/block-renderer.d.ts +402 -0
  8. package/dist/block-renderer.d.ts.map +1 -0
  9. package/dist/block-renderer.js +424 -0
  10. package/dist/block-renderer.js.map +1 -0
  11. package/dist/clipboard.d.ts +178 -0
  12. package/dist/clipboard.d.ts.map +1 -0
  13. package/dist/clipboard.js +432 -0
  14. package/dist/clipboard.js.map +1 -0
  15. package/dist/command-bus.d.ts +113 -0
  16. package/dist/command-bus.d.ts.map +1 -0
  17. package/dist/command-bus.js +70 -0
  18. package/dist/command-bus.js.map +1 -0
  19. package/dist/composition.d.ts +220 -0
  20. package/dist/composition.d.ts.map +1 -0
  21. package/dist/composition.js +271 -0
  22. package/dist/composition.js.map +1 -0
  23. package/dist/content-extraction.d.ts +69 -0
  24. package/dist/content-extraction.d.ts.map +1 -0
  25. package/dist/content-extraction.js +228 -0
  26. package/dist/content-extraction.js.map +1 -0
  27. package/dist/content-handler-file.d.ts +40 -0
  28. package/dist/content-handler-file.d.ts.map +1 -0
  29. package/dist/content-handler-file.js +91 -0
  30. package/dist/content-handler-file.js.map +1 -0
  31. package/dist/content-handler-image.d.ts +82 -0
  32. package/dist/content-handler-image.d.ts.map +1 -0
  33. package/dist/content-handler-image.js +120 -0
  34. package/dist/content-handler-image.js.map +1 -0
  35. package/dist/content-handler-url.d.ts +129 -0
  36. package/dist/content-handler-url.d.ts.map +1 -0
  37. package/dist/content-handler-url.js +244 -0
  38. package/dist/content-handler-url.js.map +1 -0
  39. package/dist/content-handlers.d.ts +67 -0
  40. package/dist/content-handlers.d.ts.map +1 -0
  41. package/dist/content-handlers.js +263 -0
  42. package/dist/content-handlers.js.map +1 -0
  43. package/dist/content-pipeline.d.ts +383 -0
  44. package/dist/content-pipeline.d.ts.map +1 -0
  45. package/dist/content-pipeline.js +232 -0
  46. package/dist/content-pipeline.js.map +1 -0
  47. package/dist/cursor-nav.d.ts +149 -0
  48. package/dist/cursor-nav.d.ts.map +1 -0
  49. package/dist/cursor-nav.js +230 -0
  50. package/dist/cursor-nav.js.map +1 -0
  51. package/dist/cursor-rect.d.ts +65 -0
  52. package/dist/cursor-rect.d.ts.map +1 -0
  53. package/dist/cursor-rect.js +98 -0
  54. package/dist/cursor-rect.js.map +1 -0
  55. package/dist/drop-indicator.d.ts +108 -0
  56. package/dist/drop-indicator.d.ts.map +1 -0
  57. package/dist/drop-indicator.js +236 -0
  58. package/dist/drop-indicator.js.map +1 -0
  59. package/dist/editor.d.ts +41 -0
  60. package/dist/editor.d.ts.map +1 -0
  61. package/dist/editor.js +710 -0
  62. package/dist/editor.js.map +1 -0
  63. package/dist/floating-toolbar.d.ts +93 -0
  64. package/dist/floating-toolbar.d.ts.map +1 -0
  65. package/dist/floating-toolbar.js +159 -0
  66. package/dist/floating-toolbar.js.map +1 -0
  67. package/dist/index.d.ts +62 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +119 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/input-bridge.d.ts +273 -0
  72. package/dist/input-bridge.d.ts.map +1 -0
  73. package/dist/input-bridge.js +884 -0
  74. package/dist/input-bridge.js.map +1 -0
  75. package/dist/link-popover.d.ts +38 -0
  76. package/dist/link-popover.d.ts.map +1 -0
  77. package/dist/link-popover.js +278 -0
  78. package/dist/link-popover.js.map +1 -0
  79. package/dist/mark-renderer.d.ts +275 -0
  80. package/dist/mark-renderer.d.ts.map +1 -0
  81. package/dist/mark-renderer.js +210 -0
  82. package/dist/mark-renderer.js.map +1 -0
  83. package/dist/perf.d.ts +145 -0
  84. package/dist/perf.d.ts.map +1 -0
  85. package/dist/perf.js +260 -0
  86. package/dist/perf.js.map +1 -0
  87. package/dist/plugin-kit.d.ts +265 -0
  88. package/dist/plugin-kit.d.ts.map +1 -0
  89. package/dist/plugin-kit.js +234 -0
  90. package/dist/plugin-kit.js.map +1 -0
  91. package/dist/plugins/alignment-plugin.d.ts +68 -0
  92. package/dist/plugins/alignment-plugin.d.ts.map +1 -0
  93. package/dist/plugins/alignment-plugin.js +98 -0
  94. package/dist/plugins/alignment-plugin.js.map +1 -0
  95. package/dist/plugins/block-utils.d.ts +113 -0
  96. package/dist/plugins/block-utils.d.ts.map +1 -0
  97. package/dist/plugins/block-utils.js +191 -0
  98. package/dist/plugins/block-utils.js.map +1 -0
  99. package/dist/plugins/blockquote-plugin.d.ts +39 -0
  100. package/dist/plugins/blockquote-plugin.d.ts.map +1 -0
  101. package/dist/plugins/blockquote-plugin.js +88 -0
  102. package/dist/plugins/blockquote-plugin.js.map +1 -0
  103. package/dist/plugins/bold-plugin.d.ts +37 -0
  104. package/dist/plugins/bold-plugin.d.ts.map +1 -0
  105. package/dist/plugins/bold-plugin.js +48 -0
  106. package/dist/plugins/bold-plugin.js.map +1 -0
  107. package/dist/plugins/callout-plugin.d.ts +100 -0
  108. package/dist/plugins/callout-plugin.d.ts.map +1 -0
  109. package/dist/plugins/callout-plugin.js +200 -0
  110. package/dist/plugins/callout-plugin.js.map +1 -0
  111. package/dist/plugins/code-block-plugin.d.ts +62 -0
  112. package/dist/plugins/code-block-plugin.d.ts.map +1 -0
  113. package/dist/plugins/code-block-plugin.js +176 -0
  114. package/dist/plugins/code-block-plugin.js.map +1 -0
  115. package/dist/plugins/code-plugin.d.ts +37 -0
  116. package/dist/plugins/code-plugin.d.ts.map +1 -0
  117. package/dist/plugins/code-plugin.js +48 -0
  118. package/dist/plugins/code-plugin.js.map +1 -0
  119. package/dist/plugins/embed-plugin.d.ts +90 -0
  120. package/dist/plugins/embed-plugin.d.ts.map +1 -0
  121. package/dist/plugins/embed-plugin.js +147 -0
  122. package/dist/plugins/embed-plugin.js.map +1 -0
  123. package/dist/plugins/font-family-plugin.d.ts +58 -0
  124. package/dist/plugins/font-family-plugin.d.ts.map +1 -0
  125. package/dist/plugins/font-family-plugin.js +57 -0
  126. package/dist/plugins/font-family-plugin.js.map +1 -0
  127. package/dist/plugins/font-size-plugin.d.ts +57 -0
  128. package/dist/plugins/font-size-plugin.d.ts.map +1 -0
  129. package/dist/plugins/font-size-plugin.js +56 -0
  130. package/dist/plugins/font-size-plugin.js.map +1 -0
  131. package/dist/plugins/heading-plugin.d.ts +52 -0
  132. package/dist/plugins/heading-plugin.d.ts.map +1 -0
  133. package/dist/plugins/heading-plugin.js +114 -0
  134. package/dist/plugins/heading-plugin.js.map +1 -0
  135. package/dist/plugins/hr-plugin.d.ts +33 -0
  136. package/dist/plugins/hr-plugin.d.ts.map +1 -0
  137. package/dist/plugins/hr-plugin.js +75 -0
  138. package/dist/plugins/hr-plugin.js.map +1 -0
  139. package/dist/plugins/image-plugin.d.ts +115 -0
  140. package/dist/plugins/image-plugin.d.ts.map +1 -0
  141. package/dist/plugins/image-plugin.js +199 -0
  142. package/dist/plugins/image-plugin.js.map +1 -0
  143. package/dist/plugins/indent-plugin.d.ts +62 -0
  144. package/dist/plugins/indent-plugin.d.ts.map +1 -0
  145. package/dist/plugins/indent-plugin.js +128 -0
  146. package/dist/plugins/indent-plugin.js.map +1 -0
  147. package/dist/plugins/index.d.ts +45 -0
  148. package/dist/plugins/index.d.ts.map +1 -0
  149. package/dist/plugins/index.js +42 -0
  150. package/dist/plugins/index.js.map +1 -0
  151. package/dist/plugins/italic-plugin.d.ts +37 -0
  152. package/dist/plugins/italic-plugin.d.ts.map +1 -0
  153. package/dist/plugins/italic-plugin.js +48 -0
  154. package/dist/plugins/italic-plugin.js.map +1 -0
  155. package/dist/plugins/link-plugin.d.ts +129 -0
  156. package/dist/plugins/link-plugin.d.ts.map +1 -0
  157. package/dist/plugins/link-plugin.js +212 -0
  158. package/dist/plugins/link-plugin.js.map +1 -0
  159. package/dist/plugins/list-plugin.d.ts +53 -0
  160. package/dist/plugins/list-plugin.d.ts.map +1 -0
  161. package/dist/plugins/list-plugin.js +309 -0
  162. package/dist/plugins/list-plugin.js.map +1 -0
  163. package/dist/plugins/mark-utils.d.ts +173 -0
  164. package/dist/plugins/mark-utils.d.ts.map +1 -0
  165. package/dist/plugins/mark-utils.js +425 -0
  166. package/dist/plugins/mark-utils.js.map +1 -0
  167. package/dist/plugins/mention-plugin.d.ts +191 -0
  168. package/dist/plugins/mention-plugin.d.ts.map +1 -0
  169. package/dist/plugins/mention-plugin.js +295 -0
  170. package/dist/plugins/mention-plugin.js.map +1 -0
  171. package/dist/plugins/strikethrough-plugin.d.ts +37 -0
  172. package/dist/plugins/strikethrough-plugin.d.ts.map +1 -0
  173. package/dist/plugins/strikethrough-plugin.js +48 -0
  174. package/dist/plugins/strikethrough-plugin.js.map +1 -0
  175. package/dist/plugins/text-color-plugin.d.ts +57 -0
  176. package/dist/plugins/text-color-plugin.d.ts.map +1 -0
  177. package/dist/plugins/text-color-plugin.js +56 -0
  178. package/dist/plugins/text-color-plugin.js.map +1 -0
  179. package/dist/plugins/underline-plugin.d.ts +37 -0
  180. package/dist/plugins/underline-plugin.d.ts.map +1 -0
  181. package/dist/plugins/underline-plugin.js +48 -0
  182. package/dist/plugins/underline-plugin.js.map +1 -0
  183. package/dist/presets.d.ts +95 -0
  184. package/dist/presets.d.ts.map +1 -0
  185. package/dist/presets.js +159 -0
  186. package/dist/presets.js.map +1 -0
  187. package/dist/renderer.d.ts +125 -0
  188. package/dist/renderer.d.ts.map +1 -0
  189. package/dist/renderer.js +415 -0
  190. package/dist/renderer.js.map +1 -0
  191. package/dist/scroll-to-cursor.d.ts +25 -0
  192. package/dist/scroll-to-cursor.d.ts.map +1 -0
  193. package/dist/scroll-to-cursor.js +59 -0
  194. package/dist/scroll-to-cursor.js.map +1 -0
  195. package/dist/selection-sync.d.ts +159 -0
  196. package/dist/selection-sync.d.ts.map +1 -0
  197. package/dist/selection-sync.js +527 -0
  198. package/dist/selection-sync.js.map +1 -0
  199. package/dist/shortcut-handler.d.ts +98 -0
  200. package/dist/shortcut-handler.d.ts.map +1 -0
  201. package/dist/shortcut-handler.js +155 -0
  202. package/dist/shortcut-handler.js.map +1 -0
  203. package/dist/toolbar.d.ts +103 -0
  204. package/dist/toolbar.d.ts.map +1 -0
  205. package/dist/toolbar.js +134 -0
  206. package/dist/toolbar.js.map +1 -0
  207. package/dist/trigger-manager.d.ts +205 -0
  208. package/dist/trigger-manager.d.ts.map +1 -0
  209. package/dist/trigger-manager.js +466 -0
  210. package/dist/trigger-manager.js.map +1 -0
  211. package/dist/types.d.ts +216 -0
  212. package/dist/types.d.ts.map +1 -0
  213. package/dist/types.js +2 -0
  214. package/dist/types.js.map +1 -0
  215. package/package.json +30 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alignment-plugin.js","sourceRoot":"","sources":["../../src/plugins/alignment-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,YAAY;IAClB,MAAM,EAAE,cAAc;IACtB,KAAK,EAAE,aAAa;IACpB,OAAO,EAAE,eAAe;CAChB,CAAC;AAeX;;;;;;GAMG;AACH,SAAS,mBAAmB,CAAC,MAAqB;IAChD,MAAM,KAAK,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC;IACjC,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACnE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL,EAAE,EAAE,gBAAgB;QACpB,IAAI,CAAC,GAAG;YACN,MAAM,UAAU,GAAgB,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;YAEvE,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;gBACnC,GAAG,CAAC,eAAe,CAAC,SAAS,SAAS,EAAE,EAAE;oBACxC,OAAO,CAAC,MAAqB;wBAC3B,MAAM,KAAK,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;wBAEvC,gEAAgE;wBAChE,MAAM,KAAK,GAAkB,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;wBAErE,MAAM,CAAC,QAAQ,CAAC;4BACd,IAAI,EAAE,iBAAiB;4BACvB,OAAO,EAAE,KAAK,CAAC,EAAE;4BACjB,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;yBACxB,CAAC,CAAC;oBACL,CAAC;oBAED,UAAU,CAAC,OAAsB;wBAC/B,OAAO,IAAI,CAAC;oBACd,CAAC;oBAED,QAAQ,CAAC,MAAqB;wBAC5B,OAAO,mBAAmB,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC;oBACnD,CAAC;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Shared utilities for block type plugins.
3
+ *
4
+ * Provides `getBlockStartOffset()` for computing a block's absolute offset,
5
+ * `getBlockAtCursor()` for resolving the block at the cursor,
6
+ * `isBlockType()` for checking the cursor block's type and attrs,
7
+ * `createToggleBlockTypeCommand()` for building block type toggle commands,
8
+ * and `setBlockType()` for dispatching type + attrs changes in a single batch.
9
+ *
10
+ * @module
11
+ */
12
+ import type { IEditorEngine, CommandDescriptor } from '@rtif-sdk/engine';
13
+ import type { Document, Block } from '@rtif-sdk/core';
14
+ /**
15
+ * Compute the absolute document offset where a block's text starts.
16
+ *
17
+ * Walks all blocks summing text lengths and virtual `\n` separators
18
+ * until the target block is found.
19
+ *
20
+ * @param doc - The document to search
21
+ * @param blockId - The ID of the target block
22
+ * @returns The absolute offset of the first character in the block
23
+ * @throws {RtifError} BLOCK_NOT_FOUND if no block with the given ID exists
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * // doc has blocks: "hello" (b1), "world" (b2)
28
+ * getBlockStartOffset(doc, 'b2'); // => 6 (5 chars + 1 virtual \n)
29
+ * ```
30
+ */
31
+ export declare function getBlockStartOffset(doc: Document, blockId: string): number;
32
+ /**
33
+ * Get the block at the current cursor position.
34
+ *
35
+ * Uses the engine's `getBlockAtOffset()` method with the focus offset
36
+ * from the current selection.
37
+ *
38
+ * @param engine - The editor engine instance
39
+ * @returns The block containing the cursor
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const block = getBlockAtCursor(engine);
44
+ * console.log(block.type); // "text"
45
+ * ```
46
+ */
47
+ export declare function getBlockAtCursor(engine: IEditorEngine): Block;
48
+ /**
49
+ * Check whether the block at the cursor position matches a given type
50
+ * and optionally specific attributes.
51
+ *
52
+ * Gets the block at the cursor via `getBlockAtCursor()`, checks that
53
+ * `block.type === blockType`, and if `attrs` is provided, verifies
54
+ * that each key/value pair matches the block's attrs.
55
+ *
56
+ * @param engine - The editor engine instance
57
+ * @param blockType - The block type string to check (e.g., "heading")
58
+ * @param attrs - Optional attributes to match against the block's attrs
59
+ * @returns `true` if the block matches the given type and attrs
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * // Check if cursor is in a heading
64
+ * isBlockType(engine, 'heading');
65
+ *
66
+ * // Check if cursor is in a level-2 heading
67
+ * isBlockType(engine, 'heading', { level: 2 });
68
+ * ```
69
+ */
70
+ export declare function isBlockType(engine: IEditorEngine, blockType: string, attrs?: Record<string, unknown>): boolean;
71
+ /**
72
+ * Create a `CommandDescriptor` that toggles a block between a specific
73
+ * type (with optional attrs) and plain `"text"`.
74
+ *
75
+ * When the block already matches the target type and attrs, it reverts
76
+ * to `"text"` with the relevant attr keys cleared. Otherwise it sets
77
+ * the block to the target type with the provided attrs.
78
+ *
79
+ * @param blockType - The block type to toggle to (e.g., "heading")
80
+ * @param attrs - Optional attributes to set when toggling on
81
+ * @returns A `CommandDescriptor` with execute, canExecute, and isActive
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * const h1Command = createToggleBlockTypeCommand('heading', { level: 1 });
86
+ * registries.registerCommand('toggleHeading1', h1Command);
87
+ * ```
88
+ */
89
+ export declare function createToggleBlockTypeCommand(blockType: string, attrs?: Record<string, unknown>): CommandDescriptor;
90
+ /**
91
+ * Dispatch `set_block_type` and optionally `set_block_attrs` in a single
92
+ * batch to change a block's type and attributes atomically.
93
+ *
94
+ * When `attrs` is provided and non-empty, both operations are dispatched
95
+ * together so they form a single undo group. When `attrs` is omitted,
96
+ * only `set_block_type` is dispatched.
97
+ *
98
+ * @param engine - The editor engine instance
99
+ * @param blockId - The ID of the block to change
100
+ * @param blockType - The new block type string
101
+ * @param attrs - Optional attributes to set on the block
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * // Change block to heading level 2
106
+ * setBlockType(engine, 'b1', 'heading', { level: 2 });
107
+ *
108
+ * // Change block type without setting attrs
109
+ * setBlockType(engine, 'b1', 'code');
110
+ * ```
111
+ */
112
+ export declare function setBlockType(engine: IEditorEngine, blockId: string, blockType: string, attrs?: Record<string, unknown>): void;
113
+ //# sourceMappingURL=block-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block-utils.d.ts","sourceRoot":"","sources":["../../src/plugins/block-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAa,MAAM,gBAAgB,CAAC;AAGjE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAc1E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,KAAK,CAE7D;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,MAAM,EACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAcT;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,MAAM,EACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,iBAAiB,CAqCnB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,IAAI,CAYN"}
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Shared utilities for block type plugins.
3
+ *
4
+ * Provides `getBlockStartOffset()` for computing a block's absolute offset,
5
+ * `getBlockAtCursor()` for resolving the block at the cursor,
6
+ * `isBlockType()` for checking the cursor block's type and attrs,
7
+ * `createToggleBlockTypeCommand()` for building block type toggle commands,
8
+ * and `setBlockType()` for dispatching type + attrs changes in a single batch.
9
+ *
10
+ * @module
11
+ */
12
+ import { blockTextLength, RtifError } from '@rtif-sdk/core';
13
+ /**
14
+ * Compute the absolute document offset where a block's text starts.
15
+ *
16
+ * Walks all blocks summing text lengths and virtual `\n` separators
17
+ * until the target block is found.
18
+ *
19
+ * @param doc - The document to search
20
+ * @param blockId - The ID of the target block
21
+ * @returns The absolute offset of the first character in the block
22
+ * @throws {RtifError} BLOCK_NOT_FOUND if no block with the given ID exists
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * // doc has blocks: "hello" (b1), "world" (b2)
27
+ * getBlockStartOffset(doc, 'b2'); // => 6 (5 chars + 1 virtual \n)
28
+ * ```
29
+ */
30
+ export function getBlockStartOffset(doc, blockId) {
31
+ let offset = 0;
32
+ for (let i = 0; i < doc.blocks.length; i++) {
33
+ const block = doc.blocks[i];
34
+ if (block.id === blockId) {
35
+ return offset;
36
+ }
37
+ offset += blockTextLength(block);
38
+ // Add virtual \n separator between blocks (not after the last block)
39
+ if (i < doc.blocks.length - 1) {
40
+ offset += 1;
41
+ }
42
+ }
43
+ throw new RtifError('BLOCK_NOT_FOUND', `Block not found: ${blockId}`);
44
+ }
45
+ /**
46
+ * Get the block at the current cursor position.
47
+ *
48
+ * Uses the engine's `getBlockAtOffset()` method with the focus offset
49
+ * from the current selection.
50
+ *
51
+ * @param engine - The editor engine instance
52
+ * @returns The block containing the cursor
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const block = getBlockAtCursor(engine);
57
+ * console.log(block.type); // "text"
58
+ * ```
59
+ */
60
+ export function getBlockAtCursor(engine) {
61
+ return engine.getBlockAtOffset(engine.state.selection.focus.offset);
62
+ }
63
+ /**
64
+ * Check whether the block at the cursor position matches a given type
65
+ * and optionally specific attributes.
66
+ *
67
+ * Gets the block at the cursor via `getBlockAtCursor()`, checks that
68
+ * `block.type === blockType`, and if `attrs` is provided, verifies
69
+ * that each key/value pair matches the block's attrs.
70
+ *
71
+ * @param engine - The editor engine instance
72
+ * @param blockType - The block type string to check (e.g., "heading")
73
+ * @param attrs - Optional attributes to match against the block's attrs
74
+ * @returns `true` if the block matches the given type and attrs
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * // Check if cursor is in a heading
79
+ * isBlockType(engine, 'heading');
80
+ *
81
+ * // Check if cursor is in a level-2 heading
82
+ * isBlockType(engine, 'heading', { level: 2 });
83
+ * ```
84
+ */
85
+ export function isBlockType(engine, blockType, attrs) {
86
+ const block = getBlockAtCursor(engine);
87
+ if (block.type !== blockType) {
88
+ return false;
89
+ }
90
+ if (attrs === undefined) {
91
+ return true;
92
+ }
93
+ for (const key of Object.keys(attrs)) {
94
+ if (block.attrs?.[key] !== attrs[key]) {
95
+ return false;
96
+ }
97
+ }
98
+ return true;
99
+ }
100
+ /**
101
+ * Create a `CommandDescriptor` that toggles a block between a specific
102
+ * type (with optional attrs) and plain `"text"`.
103
+ *
104
+ * When the block already matches the target type and attrs, it reverts
105
+ * to `"text"` with the relevant attr keys cleared. Otherwise it sets
106
+ * the block to the target type with the provided attrs.
107
+ *
108
+ * @param blockType - The block type to toggle to (e.g., "heading")
109
+ * @param attrs - Optional attributes to set when toggling on
110
+ * @returns A `CommandDescriptor` with execute, canExecute, and isActive
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * const h1Command = createToggleBlockTypeCommand('heading', { level: 1 });
115
+ * registries.registerCommand('toggleHeading1', h1Command);
116
+ * ```
117
+ */
118
+ export function createToggleBlockTypeCommand(blockType, attrs) {
119
+ return {
120
+ execute(engine) {
121
+ const block = getBlockAtCursor(engine);
122
+ const isActive = isBlockType(engine, blockType, attrs);
123
+ if (isActive) {
124
+ // Revert to plain "text" and clear the relevant attr keys
125
+ const clearAttrs = {};
126
+ if (attrs !== undefined) {
127
+ for (const key of Object.keys(attrs)) {
128
+ clearAttrs[key] = null;
129
+ }
130
+ }
131
+ const ops = [
132
+ { type: 'set_block_type', blockId: block.id, blockType: 'text' },
133
+ ];
134
+ if (Object.keys(clearAttrs).length > 0) {
135
+ ops.push({
136
+ type: 'set_block_attrs',
137
+ blockId: block.id,
138
+ attrs: clearAttrs,
139
+ });
140
+ }
141
+ engine.dispatch(ops);
142
+ }
143
+ else {
144
+ // Set to the target block type with optional attrs
145
+ setBlockType(engine, block.id, blockType, attrs);
146
+ }
147
+ },
148
+ canExecute(_engine) {
149
+ return true;
150
+ },
151
+ isActive(engine) {
152
+ return isBlockType(engine, blockType, attrs);
153
+ },
154
+ };
155
+ }
156
+ /**
157
+ * Dispatch `set_block_type` and optionally `set_block_attrs` in a single
158
+ * batch to change a block's type and attributes atomically.
159
+ *
160
+ * When `attrs` is provided and non-empty, both operations are dispatched
161
+ * together so they form a single undo group. When `attrs` is omitted,
162
+ * only `set_block_type` is dispatched.
163
+ *
164
+ * @param engine - The editor engine instance
165
+ * @param blockId - The ID of the block to change
166
+ * @param blockType - The new block type string
167
+ * @param attrs - Optional attributes to set on the block
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * // Change block to heading level 2
172
+ * setBlockType(engine, 'b1', 'heading', { level: 2 });
173
+ *
174
+ * // Change block type without setting attrs
175
+ * setBlockType(engine, 'b1', 'code');
176
+ * ```
177
+ */
178
+ export function setBlockType(engine, blockId, blockType, attrs) {
179
+ const ops = [
180
+ { type: 'set_block_type', blockId, blockType },
181
+ ];
182
+ if (attrs !== undefined && Object.keys(attrs).length > 0) {
183
+ ops.push({
184
+ type: 'set_block_attrs',
185
+ blockId,
186
+ attrs,
187
+ });
188
+ }
189
+ engine.dispatch(ops);
190
+ }
191
+ //# sourceMappingURL=block-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block-utils.js","sourceRoot":"","sources":["../../src/plugins/block-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE5D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAa,EAAE,OAAe;IAChE,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3C,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,EAAE,KAAK,OAAO,EAAE,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AAe,EACf,SAAiB,EACjB,KAA+B;IAE/B,MAAM,GAAG,GAAgB;QACvB,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,SAAS,EAAE;KAC/C,CAAC;IACF,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzD,GAAG,CAAC,IAAI,CAAC;YACP,IAAI,EAAE,iBAAiB;YACvB,OAAO;YACP,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IACD,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Blockquote block type plugin — registers the `blockquote` block type,
3
+ * `toggleBlockquote` command, and an input rule for `> ` at block start.
4
+ *
5
+ * @module
6
+ */
7
+ import type { Plugin } from '@rtif-sdk/engine';
8
+ /**
9
+ * Command name constants for the blockquote plugin.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * engine.exec(BlockquoteCommands.TOGGLE);
14
+ * ```
15
+ */
16
+ export declare const BlockquoteCommands: {
17
+ readonly TOGGLE: "toggleBlockquote";
18
+ };
19
+ /**
20
+ * Create the blockquote block type plugin.
21
+ *
22
+ * Registers:
23
+ * - Block type: `blockquote` (no default attrs, no validator)
24
+ * - Command: `toggleBlockquote` — toggle between blockquote and plain text
25
+ * - Input rule: `> ` at block start converts to blockquote
26
+ *
27
+ * @returns A plugin instance ready for `engine.use()`
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const engine = createEngine(initialDoc);
32
+ * engine.use(blockquotePlugin());
33
+ *
34
+ * // Toggle blockquote on the block at cursor
35
+ * engine.exec(BlockquoteCommands.TOGGLE);
36
+ * ```
37
+ */
38
+ export declare function blockquotePlugin(): Plugin;
39
+ //# sourceMappingURL=blockquote-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blockquote-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/blockquote-plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,kBAAkB,CAAC;AAG9D;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB;;CAErB,CAAC;AAEX;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAyDzC"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Blockquote block type plugin — registers the `blockquote` block type,
3
+ * `toggleBlockquote` command, and an input rule for `> ` at block start.
4
+ *
5
+ * @module
6
+ */
7
+ import { getBlockStartOffset, getBlockAtCursor, isBlockType, setBlockType } from './block-utils.js';
8
+ /**
9
+ * Command name constants for the blockquote plugin.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * engine.exec(BlockquoteCommands.TOGGLE);
14
+ * ```
15
+ */
16
+ export const BlockquoteCommands = {
17
+ TOGGLE: 'toggleBlockquote',
18
+ };
19
+ /**
20
+ * Create the blockquote block type plugin.
21
+ *
22
+ * Registers:
23
+ * - Block type: `blockquote` (no default attrs, no validator)
24
+ * - Command: `toggleBlockquote` — toggle between blockquote and plain text
25
+ * - Input rule: `> ` at block start converts to blockquote
26
+ *
27
+ * @returns A plugin instance ready for `engine.use()`
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const engine = createEngine(initialDoc);
32
+ * engine.use(blockquotePlugin());
33
+ *
34
+ * // Toggle blockquote on the block at cursor
35
+ * engine.exec(BlockquoteCommands.TOGGLE);
36
+ * ```
37
+ */
38
+ export function blockquotePlugin() {
39
+ return {
40
+ id: 'block-blockquote',
41
+ init(ctx) {
42
+ // ---------------------------------------------------------------
43
+ // Block type registration
44
+ // ---------------------------------------------------------------
45
+ ctx.registerBlockType('blockquote', {});
46
+ // ---------------------------------------------------------------
47
+ // toggleBlockquote command
48
+ // ---------------------------------------------------------------
49
+ ctx.registerCommand(BlockquoteCommands.TOGGLE, {
50
+ execute(engine) {
51
+ const block = getBlockAtCursor(engine);
52
+ if (isBlockType(engine, 'blockquote')) {
53
+ // Already a blockquote — revert to plain text
54
+ engine.dispatch([
55
+ { type: 'set_block_type', blockId: block.id, blockType: 'text' },
56
+ ]);
57
+ }
58
+ else {
59
+ // Set to blockquote
60
+ setBlockType(engine, block.id, 'blockquote');
61
+ }
62
+ },
63
+ canExecute(_engine) {
64
+ return true;
65
+ },
66
+ isActive(engine) {
67
+ return isBlockType(engine, 'blockquote');
68
+ },
69
+ });
70
+ // ---------------------------------------------------------------
71
+ // Input rule: > followed by space at block start
72
+ // ---------------------------------------------------------------
73
+ ctx.registerInputRule({
74
+ pattern: /^> $/,
75
+ exclusive: true,
76
+ handler(engine, match, blockId) {
77
+ const blockStart = getBlockStartOffset(engine.state.doc, blockId);
78
+ const prefixLength = match[0].length;
79
+ engine.dispatch([
80
+ { type: 'delete_text', offset: blockStart, count: prefixLength },
81
+ { type: 'set_block_type', blockId, blockType: 'blockquote' },
82
+ ]);
83
+ },
84
+ });
85
+ },
86
+ };
87
+ }
88
+ //# sourceMappingURL=blockquote-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blockquote-plugin.js","sourceRoot":"","sources":["../../src/plugins/blockquote-plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEpG;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,MAAM,EAAE,kBAAkB;CAClB,CAAC;AAEX;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO;QACL,EAAE,EAAE,kBAAkB;QACtB,IAAI,CAAC,GAAG;YACN,kEAAkE;YAClE,0BAA0B;YAC1B,kEAAkE;YAElE,GAAG,CAAC,iBAAiB,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;YAExC,kEAAkE;YAClE,2BAA2B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EAAE;qBAC7D,CAAC,CAAC;gBACL,CAAC;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Bold mark plugin — registers the `bold` mark type, `toggleMark:bold` command,
3
+ * and Cmd/Ctrl+B keyboard shortcut.
4
+ *
5
+ * @module
6
+ */
7
+ import type { Plugin } from '@rtif-sdk/engine';
8
+ /**
9
+ * Command name constants for the bold plugin.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * engine.exec(BoldCommands.TOGGLE);
14
+ * ```
15
+ */
16
+ export declare const BoldCommands: {
17
+ readonly TOGGLE: "toggleMark:bold";
18
+ };
19
+ /**
20
+ * Create the bold mark plugin.
21
+ *
22
+ * Registers:
23
+ * - Mark type: `bold` (value must be `true`)
24
+ * - Command: `toggleMark:bold`
25
+ * - Shortcut: Cmd/Ctrl+B
26
+ *
27
+ * @returns A plugin instance ready for `engine.use()`
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const engine = createEngine(initialDoc);
32
+ * engine.use(boldPlugin());
33
+ * engine.exec(BoldCommands.TOGGLE);
34
+ * ```
35
+ */
36
+ export declare function boldPlugin(): Plugin;
37
+ //# sourceMappingURL=bold-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bold-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/bold-plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG/C;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY;;CAEf,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAanC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Bold mark plugin — registers the `bold` mark type, `toggleMark:bold` command,
3
+ * and Cmd/Ctrl+B keyboard shortcut.
4
+ *
5
+ * @module
6
+ */
7
+ import { createToggleMarkCommand } from './mark-utils.js';
8
+ /**
9
+ * Command name constants for the bold plugin.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * engine.exec(BoldCommands.TOGGLE);
14
+ * ```
15
+ */
16
+ export const BoldCommands = {
17
+ TOGGLE: 'toggleMark:bold',
18
+ };
19
+ /**
20
+ * Create the bold mark plugin.
21
+ *
22
+ * Registers:
23
+ * - Mark type: `bold` (value must be `true`)
24
+ * - Command: `toggleMark:bold`
25
+ * - Shortcut: Cmd/Ctrl+B
26
+ *
27
+ * @returns A plugin instance ready for `engine.use()`
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const engine = createEngine(initialDoc);
32
+ * engine.use(boldPlugin());
33
+ * engine.exec(BoldCommands.TOGGLE);
34
+ * ```
35
+ */
36
+ export function boldPlugin() {
37
+ return {
38
+ id: 'mark-bold',
39
+ init(ctx) {
40
+ ctx.registerMarkType('bold', {
41
+ validate: (value) => value === true,
42
+ });
43
+ ctx.registerCommand(BoldCommands.TOGGLE, createToggleMarkCommand('bold'));
44
+ ctx.registerShortcut({ key: 'b', mod: true }, BoldCommands.TOGGLE);
45
+ },
46
+ };
47
+ }
48
+ //# sourceMappingURL=bold-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bold-plugin.js","sourceRoot":"","sources":["../../src/plugins/bold-plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,MAAM,EAAE,iBAAiB;CACjB,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,EAAE,EAAE,WAAW;QACf,IAAI,CAAC,GAAG;YACN,GAAG,CAAC,gBAAgB,CAAC,MAAM,EAAE;gBAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI;aACpC,CAAC,CAAC;YAEH,GAAG,CAAC,eAAe,CAAC,YAAY,CAAC,MAAM,EAAE,uBAAuB,CAAC,MAAM,CAAC,CAAC,CAAC;YAE1E,GAAG,CAAC,gBAAgB,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;QACrE,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Callout block type plugin — registers the `callout` block type with 5 variants
3
+ * (info, warning, error, success, note), three commands (`insertCallout`,
4
+ * `setCalloutVariant`, `toggleCallout`), and an input rule for `> !` at block start.
5
+ *
6
+ * Callouts are blocks with a colored border, icon, and editable content area.
7
+ * The variant determines the visual treatment (color, icon) applied by the
8
+ * block renderer in the web layer.
9
+ *
10
+ * @module
11
+ */
12
+ import type { Plugin } from '@rtif-sdk/engine';
13
+ /**
14
+ * Command name constants for the callout plugin.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * engine.exec(CalloutCommands.INSERT, { variant: 'warning' });
19
+ * engine.exec(CalloutCommands.SET_VARIANT, { variant: 'error' });
20
+ * engine.exec(CalloutCommands.TOGGLE);
21
+ * ```
22
+ */
23
+ export declare const CalloutCommands: {
24
+ readonly INSERT: "insertCallout";
25
+ readonly SET_VARIANT: "setCalloutVariant";
26
+ readonly TOGGLE: "toggleCallout";
27
+ };
28
+ /**
29
+ * The five supported callout visual variants.
30
+ *
31
+ * Each variant maps to a distinct border color and icon in the block renderer:
32
+ * - `info` — blue, informational
33
+ * - `warning` — yellow/amber, caution
34
+ * - `error` — red, danger or critical
35
+ * - `success` — green, positive confirmation
36
+ * - `note` — gray/purple, neutral annotation
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const variant: CalloutVariant = 'warning';
41
+ * ```
42
+ */
43
+ export type CalloutVariant = 'info' | 'warning' | 'error' | 'success' | 'note';
44
+ /**
45
+ * Payload for the `insertCallout` command.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * engine.exec('insertCallout', { variant: 'warning' });
50
+ * ```
51
+ */
52
+ export interface InsertCalloutPayload {
53
+ /** Callout variant. Defaults to `'info'` when omitted. */
54
+ readonly variant?: CalloutVariant;
55
+ }
56
+ /**
57
+ * Payload for the `setCalloutVariant` command.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * engine.exec('setCalloutVariant', { variant: 'error' });
62
+ * ```
63
+ */
64
+ export interface SetCalloutVariantPayload {
65
+ /** The variant to apply to the current callout block. */
66
+ readonly variant: CalloutVariant;
67
+ }
68
+ /**
69
+ * Create the callout block type plugin.
70
+ *
71
+ * Registers:
72
+ * - Block type: `callout` (attrs must have `variant` as one of 5 valid values)
73
+ * - Command: `insertCallout` — convert the block at cursor to a callout with
74
+ * an optional variant payload (defaults to `'info'`)
75
+ * - Command: `setCalloutVariant` — change the variant attr on the current
76
+ * callout block (only executable when cursor is in a callout)
77
+ * - Command: `toggleCallout` — toggle between callout (info variant) and
78
+ * plain text
79
+ * - Input rule: `> !` at the start of a block converts to a callout with
80
+ * `'info'` variant
81
+ *
82
+ * @returns A plugin instance ready for `engine.use()`
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const engine = createEngine(initialDoc);
87
+ * engine.use(calloutPlugin());
88
+ *
89
+ * // Convert block at cursor to a warning callout
90
+ * engine.exec(CalloutCommands.INSERT, { variant: 'warning' });
91
+ *
92
+ * // Change variant of the current callout
93
+ * engine.exec(CalloutCommands.SET_VARIANT, { variant: 'error' });
94
+ *
95
+ * // Toggle callout on/off (uses 'info' variant when toggling on)
96
+ * engine.exec(CalloutCommands.TOGGLE);
97
+ * ```
98
+ */
99
+ export declare function calloutPlugin(): Plugin;
100
+ //# sourceMappingURL=callout-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callout-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/callout-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,kBAAkB,CAAC;AAG9D;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe;;;;CAIlB,CAAC;AAEX;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE/E;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,0DAA0D;IAC1D,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC;CACnC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,wBAAwB;IACvC,yDAAyD;IACzD,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;CAClC;AA2BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAsItC"}